0

After doing a bit of logistic regression Im trying to do Lasso regression but on typing various commands I keep getting object not found errors Here is my code so far

data <- read.csv("ahw.csv", 
+                  colClasses = c("factor",
+                                 rep("numeric", 15)))

Which gives me

 $ PlacedN: Factor w/ 2 levels "0","1": 1 1 1 1 1 2 1 1 1 1 ...
 $ TrA    : num  9 13 11 9 -1 13 10 10 10 6 ...
  $ JoA    : num  0 2 0 10 6 15 8 9 9 6 ...
  $ aPr    : num  0 0 0 0 0 0 0 0 0 0 ...
  $ bPr    : num  0 1 0 0 1 0 0 0 0 0 ...
 $ mPr    : num  0 0 0 0 1 0 0 0 0 0 ...
 $ Vdw    : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALL    : num  32 46 15 16 48 50 32 9 28 4 ...
 $ COD    : num  -1 80 0 25 -1 50 47 -1 -1 -1 ...
 $ DIS.   : num  32 46 23 15 48 50 32 9 28 0 ...
 $ cIM    : num  -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
 $ cFE    : num  -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
  $ LAT    : num  38 38 9 20 61 58 37 12 25 5 ...
  $ CLA    : num  40 50 9 25 -1 75 61 -1 -1 -1 ...
  $ CLC    : num  -1 -1 0 25 -1 75 61 -1 -1 -1 ...
  $ LAC    : num  38 50 9 25 -1 60 61 -1 -1 -1 ...

Obviously I can call the Logistic formula up using

est <- glm(PlacedN ~ ., data=data, family="binomial")
summary(est)

So basically what is my next step to do LASSO (with logit) and also get the coefficients and any nice graphs after it

There are a few packages out there which is confusing a beginner like me

Thanks in Advance

Michael

Michael
  • 13
  • 1
  • 4

1 Answers1

2

The glmnet package should be useful. There is a great tutorial by the authors. But, here is a quick start using your code.

require(glmnet)
est <- glmnet(as.matrix(data[,2:16]), data$PlacedN , family="binomial")
summary(est)
plot(est)
last <- dim(coef(est))[2]
coef(est)[last]

Hope this helps!

user51855
  • 369
  • 1
  • 6