Yi
2010-Aug-07 21:12 UTC
[R] plot the dependent variable against one of the predictors with other predictors as constant
Hi, folks, Happy work in weekends >_< My question is how to plot the dependent variable against one of the predictors with other predictors as constant. Not for the original data, but after prediction. It means y is the predicted value of the dependent variables. The constane value of the other predictors may be the average or some fixed value. ####### y=1:10 x=10:1 z=2:11 lin_model=lm(z~x+y) x_new=11:2 ####### How to plot predicted value of z from the regression model with x takes x_new and y as a constant (let's say y=1) I am thinking about using 'predict' command to generate the prediction of z with the new data.frame but there should be a better way. Thanks all. Yi [[alternative HTML version deleted]]
Frank Harrell
2010-Aug-07 21:46 UTC
[R] plot the dependent variable against one of the predictors with other predictors as constant
There are many ways to do this. Here is one. install.packages('rms') require(rms) dd <- datadist(x, y); options(datadist='dd') f <- ols(z ~ x + y) plot(Predict(f)) # plot all partial effects plot(Predict(f, x)) # plot only the effect of x plot(Predict(f, y)) # plot only the effect of y f <- ols(z ~ pol(x,2)*pol(y,2) # repeat, not assuming linearity Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University On Sat, 7 Aug 2010, Yi wrote:> Hi, folks, > > Happy work in weekends >_< > > My question is how to plot the dependent variable against one of the > predictors with other predictors as constant. Not for the original data, but > after prediction. It means y is the predicted value of the dependent > variables. The constane value of the other predictors may be the average or > some fixed value. > > ####### > y=1:10 > x=10:1 > z=2:11 > lin_model=lm(z~x+y) > x_new=11:2 > ####### > > > How to plot predicted value of z from the regression model with x takes > x_new and y as a constant (let's say y=1) > > > I am thinking about using 'predict' command to generate the prediction of z > with the new data.frame but there should be a better way. > > Thanks all. > > Yi > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Bert Gunter
2010-Aug-08 14:53 UTC
[R] plot the dependent variable against one of the predictors with other predictors as constant
> I am thinking about using 'predict' command to generate the prediction of z > with the new data.frame but there should be a better way.I'm puzzled. Why would you think that? This is the canonical way to do predictions in R. Bert Gunter Genentech Nonclinical Statistics
Greg Snow
2010-Aug-09 18:29 UTC
[R] plot the dependent variable against one of the predictors with other predictors as constant
Look at the TkPredict and Predict.Plot functions in the TeachingDemos package as a couple of options. -- 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 Yi > Sent: Saturday, August 07, 2010 3:13 PM > To: R (r-help at R-project.org) > Subject: [R] plot the dependent variable against one of the predictors > with other predictors as constant > > Hi, folks, > > Happy work in weekends >_< > > My question is how to plot the dependent variable against one of the > predictors with other predictors as constant. Not for the original > data, but > after prediction. It means y is the predicted value of the dependent > variables. The constane value of the other predictors may be the > average or > some fixed value. > > ####### > y=1:10 > x=10:1 > z=2:11 > lin_model=lm(z~x+y) > x_new=11:2 > ####### > > > How to plot predicted value of z from the regression model with x takes > x_new and y as a constant (let's say y=1) > > > I am thinking about using 'predict' command to generate the prediction > of z > with the new data.frame but there should be a better way. > > Thanks all. > > Yi > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.