predict.glm & newdata

5 messages Options
Embed this post
Permalink
Tom Guston

predict.glm & newdata

Reply Threaded More More options
Print post
Permalink

Hi all -

I'm stumped by the following

mdl <- glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS
yhat <- predict(mdl) WORKS
yhat <- predict(mdl,newdata = df) FAILS

Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) :
  subscript out of bounds


I've tried without offset, quoting binomial. The offset variable ofst IS in df.

Previous postings indicate possible names(df) problems (renaming factor levels?) but I'm using the same data.frame for the newdata option.

Thank you in advance for any pointers.

Tom.




_________________________________________________________________
Going green? See the top 12 foods to eat organic.

1N1653A
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Daniel Malter

Re: predict.glm & newdata

Reply Threaded More More options
Print post
Permalink
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              


-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im
Auftrag von Tom Guston
Gesendet: Friday, April 04, 2008 1:29 PM
An: [hidden email]
Betreff: [R] predict.glm & newdata


Hi all -

I'm stumped by the following

mdl <- glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS yhat
<- predict(mdl) WORKS yhat <- predict(mdl,newdata = df) FAILS

Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) :
  subscript out of bounds


I've tried without offset, quoting binomial. The offset variable ofst IS in
df.

Previous postings indicate possible names(df) problems (renaming factor
levels?) but I'm using the same data.frame for the newdata option.

Thank you in advance for any pointers.

Tom.




_________________________________________________________________
Going green? See the top 12 foods to eat organic.

1N1653A
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Yasir Kaheil

Re: predict.glm & newdata

Reply Threaded More More options
Print post
Permalink
You could just say:
yhat=predict(reg1,x2)
the function predict will assing x2 to 'newdata' by default.
thanks



Daniel Malter wrote:
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              


-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org] Im
Auftrag von Tom Guston
Gesendet: Friday, April 04, 2008 1:29 PM
An: r-help@r-project.org
Betreff: [R] predict.glm & newdata


Hi all -

I'm stumped by the following

mdl <- glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS yhat
<- predict(mdl) WORKS yhat <- predict(mdl,newdata = df) FAILS

Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) :
  subscript out of bounds


I've tried without offset, quoting binomial. The offset variable ofst IS in
df.

Previous postings indicate possible names(df) problems (renaming factor
levels?) but I'm using the same data.frame for the newdata option.

Thank you in advance for any pointers.

Tom.




_________________________________________________________________
Going green? See the top 12 foods to eat organic.

1N1653A
        [[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.

______________________________________________
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.
DAVID ARTETA GARCIA

tukey biweight of vector

Reply Threaded More More options
Print post
Permalink
Dear list,

I have a vector of readings of length 4640

length(int)
[1] 4640

I would like to calculate Tukey´s biweight using the tbrm() function  
for the first ten values, the next ten values,etc and store it in  
another vector of length 464. Can anyone help me?

Thanks in advance

David

______________________________________________
[hidden email] 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.
Bert Gunter

Re: tukey biweight of vector

Reply Threaded More More options
Print post
Permalink
apply(matrix(int,nr=10),2,trbm)

?apply

-- Bert Gunter
Genentech Nonclinical Statistics

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of DAVID ARTETA GARCIA
Sent: Monday, May 05, 2008 8:19 AM
To: [hidden email]
Subject: [R] tukey biweight of vector

Dear list,

I have a vector of readings of length 4640

length(int)
[1] 4640

I would like to calculate Tukey´s biweight using the tbrm() function  
for the first ten values, the next ten values,etc and store it in  
another vector of length 464. Can anyone help me?

Thanks in advance

David

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.