On Aug 4, 2011, at 5:41 PM, Paul Smith wrote:

> Dear All,
> 
> 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?
> 
> Thanks in advance,
> 
> Paul

Hi Paul,

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.

HTH,

Marc Schwartz

______________________________________________
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