On Fri, Aug 5, 2011 at 12:02 AM, Marc Schwartz <marc_schwa...@me.com> wrote: >> Can the x matrix in the glmnet() function of glmnet package be a >> data.frame with numeric columns and factor columns? I am asking this >> because I have a model with both numeric and categorical predictors, >> which I would like to study with glmnet. I have already tried to use a >> data.frame, but with no success -- as far as I know, the matrix object >> can only have data of a single type. Is there some way of >> circumventing this problem? > > My recollection is that you would use ?model.matrix on the data frame to > create the requisite matrix input for glmnet(). > > The caution however, is that glmnet() standardizes the input covariates, > which is not appropriate for factors. Thus, you would want to set > 'standardize = FALSE' and use appropriate methods in pre-processing > continuous variables.
Again, Mark, thanks a lot for your so helpful answer -- I completely ignored model.matrix(). Paul ______________________________________________ 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.