Skip to content

Commit

Permalink
use multinom instead of glmnet
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkowa committed Oct 24, 2014
1 parent 1ff93ab commit e0ab2e9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Imports:
robustbase,
stats,
sp,
vcd,MASS,nnet,e1071,methods,Rcpp,glmnet
vcd,MASS,nnet,e1071,methods,Rcpp
Description: This package introduces new tools for the visualization of missing
and/or imputed values, which can be used for exploring the data and the
structure of the missing and/or imputed values. Depending on this structure
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import(Rcpp)
import(colorspace)
import(data.table)
import(e1071)
import(glmnet)
import(grDevices)
import(grid)
import(methods)
Expand Down
1 change: 0 additions & 1 deletion R/VIM-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @import grid
#' @import robustbase
#' @import colorspace
#' @import glmnet
#' @importFrom car bcPower
#' @importFrom car powerTransform
#' @importFrom vcd mosaic
Expand Down
9 changes: 4 additions & 5 deletions R/regressionImp.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ regressionImp_work <- function(formula, family, robust, data,imp_var,imp_suffix,
else
mod <- glm(form,data=data,family=fam)
}else{
fam <- "multinomial"
TFna <- TFna2&!is.na(data[,lhsV])
mod <- glmnet(model.matrix(form,data[TFna,]),data[TFna,lhsV],family=fam)
mod <- multinom(form,data[TFna,])
}
}
if(imp_var){
Expand All @@ -112,11 +111,11 @@ regressionImp_work <- function(formula, family, robust, data,imp_var,imp_suffix,
tmp <- data[TFna3,]
tmp[,lhsV] <- 1
if(nLev>2){
modcv <- cv.glmnet(model.matrix(form,data[TFna,]),data[TFna,lhsV],family="multinomial")
pre <- predict(mod,newx=model.matrix(form,tmp),type="response",s=modcv$lambda.1se)[,,1]

if(mod_cat){
pre <- levels(data[,lhsV])[apply(pre,1,which.max)]
pre <- predict(mod,new.data=tmp)
}else{
pre <- predict(mod,new.data=tmp,type="probs")
pre <- levels(data[,lhsV])[apply(pre,1,function(x)sample(1:length(x),1,prob=x))]
}
}else if(nLev==2){
Expand Down

0 comments on commit e0ab2e9

Please sign in to comment.