predict.glm
On Jan 16, 2010, at 1:34 PM, Maurice Charbit wrote:
Hi, See below I reply your message for <https://stat.ethz.ch/pipermail/r-help/2008-April/160966.html
[R] predict.glm & newdata posted on Fri Apr 4 21:02:24 CEST 2008
You say it ##works fine but it does not: if you look at the length of yhat2, you will find 100 and not 200 as expected. In fact predict(reg1, data=x2) gives the same results as predict(reg1). So I am still looking for a solution of this problem.
You are replying to a posting that is almost two years old. The posting back then was incomplete in that y1 was never defined. Why not post a more complete and updated question?
David. > > > best regards > > Maurice > > =========== > > Hi, > > could it be the "newdata" argument? When I run predict with the > newdata > argument, I get an error message - a different one though. The > second reason > might be that your dataset is named df, which is defined as a > function an > may produce problems. Try renaming the dataset. > > yhat=predict(reg1,newdata=x2) > > x1=seq(1:100) > r.norm1=rnorm(100,0,20) > x1=r.norm1+x1 > > x2=x1*2 > r.norm2=rnorm(200,0,20) > x2=r.norm2+x2 > > reg1=glm(y1~x1,binomial) > yhat=predict(reg1) ##prediction works fine > yhat=predict(reg1,newdata=x2) ##gives error message because of > "newdata" > >> Error in eval(predvars, data, env) : > numeric 'envir' arg not of length one > > yhat=predict(reg1,data=x2) ##works fine > > ##using offset > > ofst=rep(0.5,100) > > reg1=glm(y1~x1,binomial,offset=ofst) > yhat=predict(reg1) > yhat1=predict(reg1,newdata=x2) ##gives error message > yhat2=predict(reg1,data=x2) ##works fine > > > % ================================================= > % Maurice CHARBIT > % Ecole Nationale Sup?rieure des T?l?communications > % D?partement TSI > % 37,39 rue Dareau, pi?ce A321 > % 75634 - PARIS cedex 13 FRANCE > % email: maurice.charbit at telecom-paristech.fr > % Fax: (33) (0)1 45 81 71 44 > % Phone: (33) (0)1 45 81 71 78 > %==================================================| > [[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. David Winsemius, MD Heritage Laboratories West Hartford, CT