s-news
[Top] [All Lists]

Re: predict.lm() - Seems not to accept the dataframe parameter

To: "Richard M. Heiberger" <rmh@temple.edu>
Subject: Re: predict.lm() - Seems not to accept the dataframe parameter
From: Silent Killer <thesilentkiller@gmail.com>
Date: Sun, 24 Apr 2005 00:01:34 -0400
Cc: s-news@lists.biostat.wustl.edu
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=S9ZG0aZE0nyAo57AF8+bq+Gvk6NPBwPbZS0QDHhfmKyOxfILvJY2+gla898CIk5uhHqeBKOnKtUjXBUex7/3kF4LND55AzL8pT7QqqCHse4mqNJwBYVvluV0JgwlIVshTK2taAGE2d8Hy7gqfcuBK7TLAWNyEpxBkCArZLT++Lg=
In-reply-to: <dfaa07a1.f1d07a51.81b9400@po-d.temple.edu>
References: <dfaa07a1.f1d07a51.81b9400@po-d.temple.edu>
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

I decoupled the dataset from the formula, as you had explained, and now predict works fine. I am also switching over to the convention of using <- and not _

As for the variable names, I intentionally changed it in the sample I used cuz I didnt wanna make known my work :)

Thanks for your suggestions, and your quick reply.

Thanks,
Vasanth

Richard M. Heiberger wrote:

dataset1 <- data.frame(Var1=rnorm(100), Var2=rnorm(100), Var3=rnorm(100))

## Please use " <- ", with the spaces surrounding the arrow.  Please
## do not use "_".  The arrow is legible, the underscore is not---and
## worse, confuses people who think the underscore is an alphabetical
## character (as it is in SAS and in R 2.x.x).
Poly1 <- lm(dataset1$Var1 ~ poly(dataset1$Var2, 40) + poly(dataset1$Var3, 40),
           singular.ok = T)
formula(Poly1)

## note that you have placed dataset1 in the formula.
## therefore the prediction was based on dataset1.
## > formula(Poly1)
## dataset1$Var1 ~ poly(dataset1$Var2, 40) + poly(dataset1$Var3, 40)
## >

## We recommend that you use meaningful variable names.
names(dataset1) <- c("height","weight","diameter")

## The correct way to do this is to use the data= argument.
Poly1 <- lm(height ~ poly(weight, 40) + poly(diameter, 40),
           data=dataset1,
           singular.ok = T)
formula(Poly1)

## now predict works as you wish it to work.
dataset2 <- dataset1
dataset2$weight <- dataset2$weight+10
dataset2$diameter <- dataset2$diameter+10
predict(Poly1)
predict(Poly1, newdata=dataset2)



<Prev in Thread] Current Thread [Next in Thread>