[R] Use predict.lm

Gabor Grothendieck ggrothendieck at gmail.com
Wed May 3 00:45:51 CEST 2006


Try this:

# regression of Sepal.Length on cols 2 and 4 using first 100 rows
iris.lm <- lm(Sepal.Length ~ ., iris[,c(1,2,4)], subset = 1:100)

# now do it with next 50 rows
predict(update(iris.lm, subset = 101:150))

# double check - this gives same result as last line
predict(lm(Sepal.Length ~ ., iris[,c(1,2,4)], subset = 101:150))


On 5/2/06, Jiang, Jincai (Institutional Securities Management)
<Jincai.Jiang at morganstanley.com> wrote:
> Hi All,
>
> I created a two variable lm() model
>
> slm<-lm(y[1:3000,8]~y[1:3000,12]+y[1:3000,15])
>
> I made two predictions
>
> predict(slm,newdata=y[201:3200,])
> predict(slm,newdata=y[601:3600,])
>
> there is no error message for either of these.
> the results are identical, and identical to slm$fitted as well.
>
> if this is not the right way to apply the model coefficients to a new
> set of inputs, what is the right way?
>
> Thank you
>
> Regards,
>
> Jincai Jiang
> (Office) 212-761-3984
>
> --------------------------------------------------------
> This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. Any ModelWare, research or other information referenced herein is subject to the ClientLink and ModelWare terms of use including all applicable disclosures and disclaimers. The information provided speaks only as of its date. We have not undertaken, and will not undertake, any duty to update the information or otherwise advise you of changes in our opinion or in the research or information. Continued access to the research and other information is provided for your convenience only, and is not a republication or reconfirmation of the opinions or information contained therein. For additional information and important disclosures, contact me or see the ModelWare website. Past performance is not indicative of future returns. This communication is !
>  solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules).
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list