1

I am trying to do a ridge regression using the codes below with GenCont data in the library ridge

library(ridge)
data(GenCont)
GenCont_df <- as.data.frame(GenCont)
GenCont_df$SNP1 <- as.factor(GenCont_df$SNP1)
mod2 <- linearRidge(Phenotypes ~ SNP1+SNP2, data = GenCont_df)
predict(mod2, GenCont_df, na.action = na.pass, all.coef = FALSE,scaling ="scale")

But if I used dummy variables in the model I get this error

Error in X[, ll] : subscript out of bounds

Is there a way to predict dummy variables in Ridge regression in R?

jbest
  • 640
  • 1
  • 10
  • 28
  • It would appear ridge regression uses PCA at some point, for which categorical variables are hard to translate into metrics that can be expressed in a meaningful distance. – Roman Luštrik Jun 30 '15 at 07:07
  • In that case is there a short cut in R where I can recode my dummy variables. Let say I have category A,B and C, I want to create a column for them containing 1 and 0 – jbest Jun 30 '15 at 07:36
  • Nevermind, `model.matrix` seems to work – jbest Jun 30 '15 at 08:11
  • Can you Explain how you fixed the error @jbest? – mms Oct 24 '18 at 20:25

0 Answers0