Dear all,

I am trying to iterate an elastic net regression method on a matrix

1) Each column of the matrix ( nxp) will act as a response (y) and rest of
the variables (columns) which means p-1 will act as predictor set

2) i want to store selected variables as matrix

I wrote a code. Please help me to automate this procedure

# install packages for analysis

 rm(list = ls())

 library(caret)

 library(glmnet)

 X<-matrix(rnorm(100*500),nrow=100)


 y<-X[,1]  # I want automatically it will take next column as a response
means untill 500 columns

 X1<-X[,-1] # If I use first column as a response it should delete first
column from the matrix

 dim(X1)


 ### Applicarion of the Elastic net for selecting the genes


con<-trainControl(method="cv",number=10)


fit_data<-train(X1,
y,method="glmnet",metric="RMSE",trControl=con,tuneLength = 10)

glmnetcalc<-glmnet(X1,y,alpha=fit_data$finalModel$tuneValue$.alpha)

fitcoef<-predict(glmnetcalc,s=fit_data$finalModel$tuneValue$.alpha,type="coefficients")

CoefEN_1<-as.matrix(fitcoef)

write.table(CoefEN_1, "varSelect_1.txt")  # I want to store the non zero
values in a matrix



thanks

Nico

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to