Ricardo Gomez
2008-Dec-17 15:46 UTC
[R] PREDICT NEW VALUES FROM REGRESSION MODEL, EST. ST.ERROR, AND CI
Greetings, I'd be grateful if a good Samaritan helps me to approach this problem.... with my data, I've created the following model lm(formula = OUTCOME ~ VAR1 + VAR2) summary(model) Call: lm(formula = OUTCOME ~ VAR1 + VAR2) Residuals: Min 1Q Median 3Q Max -1.4341 -0.3621 0.1879 0.4994 0.7696 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.89020 0.26826 7.046 5.92e-07 *** VAR1 0.04725 0.06001 0.787 0.440 VAR2 0.04139 0.05655 0.732 0.472 Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Residual standard error: 0.6618 on 21 degrees of freedom Multiple R-squared: 0.9474, Adjusted R-squared: 0.9424 F-statistic: 189.2 on 2 and 21 DF, p-value: 3.696e-14 but now, I need to predict OUTCOME (Y) when VAR1=8 and VAR2 =64; estimate the standard error of the predicted value, and construct a 95% CI Your help is much appreciated RG ***************************************** Ricardo L Gomez Center for International Education University of Massachusetts-Amherst Telephone: (413)545-0465 | Fax: (413)545-1263 Web Address http://www.umass.edu/cie E-mail: cie at educ.umass.edu Get the world's best email - http://nz.mail.yahoo.com/
Greg Snow
2008-Dec-17 15:51 UTC
[R] PREDICT NEW VALUES FROM REGRESSION MODEL, EST. ST.ERROR, AND CI
?predict.lm -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Ricardo Gomez > Sent: Wednesday, December 17, 2008 8:47 AM > To: R-help at r-project.org > Subject: [R] PREDICT NEW VALUES FROM REGRESSION MODEL, EST. ST.ERROR, > AND CI > > > Greetings, > > I'd be grateful if a good Samaritan helps me to approach this > problem.... > > with my data, I've created the following model > > lm(formula = OUTCOME ~ VAR1 + VAR2) > summary(model) > > Call: > lm(formula = OUTCOME ~ VAR1 + VAR2) > > Residuals: > Min 1Q Median 3Q Max > -1.4341 -0.3621 0.1879 0.4994 0.7696 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 1.89020 0.26826 7.046 5.92e-07 *** > VAR1 0.04725 0.06001 0.787 0.440 > VAR2 0.04139 0.05655 0.732 0.472 > > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > Residual standard error: 0.6618 on 21 degrees of freedom > Multiple R-squared: 0.9474, Adjusted R-squared: 0.9424 > F-statistic: 189.2 on 2 and 21 DF, p-value: 3.696e-14 > > but now, I need to predict OUTCOME (Y) when VAR1=8 and VAR2 =64; > estimate the standard error of the predicted value, and construct a 95% > CI > > Your help is much appreciated > > RG > ***************************************** > Ricardo L Gomez > Center for International Education > University of Massachusetts-Amherst > Telephone: (413)545-0465 | Fax: (413)545-1263 > Web Address http://www.umass.edu/cie > E-mail: cie at educ.umass.edu > > > > Get the world's best email - http://nz.mail.yahoo.com/ > > ______________________________________________ > 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.
Paul Teetor
2008-Dec-18 03:57 UTC
[R] PREDICT NEW VALUES FROM REGRESSION MODEL, EST. ST.ERROR, AND CI
First, package the new values of your predictor variables into a data frame: data.frame(VAR1=8, VAR2=64) Then, use the predict() method to apply the model to the predictor values: predict(model, newdata=data.frame(VAR1=8, VAR2=64)) Finally, tell the predict() method that these are new observations, not original observations, and you want the confidence interval of the prediction: predict(model, newdata=data.frame(VAR1=8, VAR2=64), interval="pred", level=0.95) That should print the fitted value for OUTCOME, the lower bound, and the upper bound. To see the standard error, include "predict(..., st.fit=TRUE)" in your call to predict(). Hope that helps. Paul Paul Teetor Elgin, IL USA [[alternative HTML version deleted]]