Dear R-Users, How can I put a pre-defined regression model into to an object of class lm in order to use the predict.lm function. A simplified example: I would normally run a regression analysis on a dataset,> germany<-lm(RENT~AGE1, in.mi01)> summary(germany)Call: lm(formula = RENT ~ AGE1, data = in.mi01) Residuals: Min 1Q Median 3Q Max -12.193 -3.646 -1.009 2.101 49.025 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 13.283639 0.063020 210.78 <2e-16 *** AGE1 -0.091030 0.003231 -28.17 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 6.044 on 19802 degrees of freedom Multiple R-Squared: 0.03854, Adjusted R-squared: 0.03849 F-statistic: 793.7 on 1 and 19802 DF, p-value: < 2.2e-16 and then use the predict.lm function which uses the above specified regression equation: RENT=13.283639-0.091030*AGE1 But I want to skip the lm function and specify my own regression equation RENT= 15 -0.15*AGE1 and then use the predict.lm function. However, in order to use the predict.lm function I need an object of class lm. Is there any way to do so? Or maybe somebody has another solution? Thanks in advance, Simon [[alternative HTML version deleted]]
>>> "Simon P. Kempf" <simon.kempf at web.de> 2/9/2007 1:36 am >>> asked<<<< But I want to skip the lm function and specify my own regression equation RENT= 15 -0.15*AGE1 and then use the predict.lm function. However, in order to use the predict.lm function I need an object of class lm. Is there any way to do so? Or maybe somebody has another solution?>>>Maybe I am missing something, but why not just write the formula without the predict.lm? e.g <<< AGE1 <- c(18, 19, 20, 21) RENT= 15 -0.15*AGE1 RENT>>>Peter Thanks in advance, Simon [[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 and provide commented, minimal, self-contained, reproducible code.
Simon P. Kempf <simon.kempf <at> web.de> writes: [SNIP]> > But I want to skip the lm function and specify my own regression equation > RENT= 15 -0.15*AGE1 and then use the predict.lm function. However, in order > to use the predict.lm function I need an object of class lm. Is there any > way to do so? Or maybe somebody has another solution? > > Thanks in advance, > > SimonHere is one way. Take a look at help(offset), help(lm), and help(lm.predict).> xx <- runif(30) > yy <- rnorm(30) > mydata<-data.frame(xx,yy) > lm(yy~offset(15*rep(1,30))+offset(-0.15*xx)-1,mydata)Mark Lyman