# Re: [R] Plotting a cubic line from a multiple regression

From: <Richard.Cotton_at_hsl.gov.uk>
Date: Thu, 29 May 2008 17:30:48 +0100

> I'm attempting to plot a cubic relationship between two variables
> controlling for the effects of a third variable. In this short
> example, I'm trying to use AGE to predict CORTEX while controlling for
> the effects of TIV (total intracranial volume):
>
> ########################
> cortex = rnorm(100, mean=0.5, sd=0.5)
> age = rnorm(100, mean=10, sd=2)
> tiv = rnorm(100, mean=1000, sd=100)
>
> ##
> ## simple regression (ignoring TIV) works
> ##
> cortex.lm = lm(cortex ~ poly(age, degree=3))
> plot(age, cortex)
> pseudo.x = seq(min(age)-2, max(age)+2, len=200)
> lines(pseudo.x, predict(cortex.lm, data.frame(age=pseudo.x)))
>
> ##
> ## multiple regression (accounting for TIV) fails
> ##
> cortex.lm = lm(cortex ~ poly(age, degree=3) + tiv)
> plot(age, cortex)
> pseudo.x = seq(min(age)-2, max(age)+2, len=200)
> lines(pseudo.x, predict(cortex.lm, data.frame(age=pseudo.x)))
> ########################
>
> Although the last 'lines' command fails, summary(cortex.lm) does give
> me reasonable coefficients for the multiple regression. Can anyone
> advise me if (1) this is at all a legitimate procedure, and (2) how to
> draw the cubic function that fits the multiple regression?

Regards,
Richie.

Mathematical Sciences Unit
HSL

ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}

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. Received on Thu 29 May 2008 - 17:57:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 04:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.