[R] plot the dependent variable against one of the predictors with other predictors as constant

Frank Harrell f.harrell at vanderbilt.edu
Sat Aug 7 23:46:39 CEST 2010

```There are many ways to do this.  Here is one.

install.packages('rms')
require(rms)
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