[R] Different results of coefficients by packages penalized and glmnet
Andrew Robinson
A.Robinson at ms.unimelb.edu.au
Mon May 2 01:22:14 CEST 2011
Hi Yao,
I can't answer that question, but I offer the following thoughts for
your consideration.
Generally it's best to approach the package maintainers directly with
questions like these. You can find their contact details in the
package documentation.
Also, you will want to make sure that you provide commented, minimal,
self-contained, reproducible code. I can't run the code below because
I don't have the data. Try to create an example that shows your
problem using data that will be readily available to the maintainers.
Perhaps one of the packages provides a n example dataset --- that
would be best. If not, you should write code to generate an example
dataset, or be prepared to share your own data.
I hope that this helps,
Andrew
On Sun, May 01, 2011 at 05:01:54PM +0800, zhu yao wrote:
> Dear R users:
>
> Recently, I learn to use penalized logistic regression. Two packages
> (penalized and glmnet) have the function of lasso.
> So I write these code. However, I got different results of coef. Can someone
> kindly explain.
>
> # lasso using penalized
> library(penalized)
> pena.fit2<-penalized(HRLNM,penalized=~CN+NoSus,lambda1=1,model="logistic",standardize=TRUE)
> pena.fit2
> coef(pena.fit2)
> opt<-optL1(HRLNM,penalized=~CN+NoSus,fold=5)
> opt$lambda
> coef(opt$fullfit)
> prof<-profL1(HRLNM,penalized=~CN+NoSus,fold=opt$fold,steps=20)
> plot(prof$lambda, prof$cvl, type="l")
> plotpath(prof$fullfit)
> pena.fit2<-penalized(HRLNM,penalized=~CN+NoSus,lambda1=opt$lambda,model="logistic",standardize=TRUE,steps=20)
> plotpath(pena.fit2)
> pena.fit2<-penalized(HRLNM,penalized=~CN+NoSus,lambda1=opt$lambda,model="logistic",standardize=TRUE)
> coef(pena.fit2)
>
>
> #lasso using gamnet
> library(glmnet)
> factors<-matrix(c(CN,NoSus),ncol=2)
> colnames(factors)<-c("CN","NoSus")
> glmn.fit2<-glmnet(x=factors,y=HRLNM,family="binomial")
> cvglmnet<-cv.glmnet(x=factors,y=HRLNM,family="binomial",nfolds=5)
> plot(cvglmnet)
> cvglmnet$lambda.min
> which(cvglmnet$lambda==cvglmnet$lambda.min)
> glmn.fit2<-glmnet(x=factors,y=HRLNM,family="binomial",lambda=cvglmnet$lambda.min)
> coef(glmn.fit2)
>
>
>
> Thanks a lot
>
> btw: how to calculate the C.I. of coefs?
>
>
> *Yao Zhu*
> *Department of Urology
> Fudan University Shanghai Cancer Center
> Shanghai, China*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
--
Andrew Robinson
Program Manager, ACERA
Department of Mathematics and Statistics Tel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia (prefer email)
http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599
http://www.acera.unimelb.edu.au/
Forest Analytics with R (Springer, 2011)
http://www.ms.unimelb.edu.au/FAwR/
Introduction to Scientific Programming and Simulation using R (CRC, 2009):
http://www.ms.unimelb.edu.au/spuRs/
More information about the R-help
mailing list