[R] plot the dependent variable against one of the predictors with other predictors as constant
f.harrell at vanderbilt.edu
Sat Aug 7 23:46:39 CEST 2010
There are many ways to do this. Here is one.
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.
> 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.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help