[R] how to draw confidence interval lines of a fitted curve of polynominal regression

Rui Barradas ruipbarradas at sapo.pt
Thu Feb 7 12:56:44 CET 2013


Hello,

You should follow the posting guide and provide us with a data and code 
example.

# Make up some data
x <- seq(0, 1, length.out = 20)
y <- x^2 + rnorm(20)

# fit a quadratic
model <- lm(y ~ I(x^2))
fitted <- predict(model, interval = "confidence")

# plot the data and the fitted line
plot(x, y)
lines(x, fitted[, "fit"])

# now the confidence bands
lines(x, fitted[, "lwr"], lty = "dotted")
lines(x, fitted[, "upr"], lty = "dotted")


Hope this helps,

Rui Barradas
Em 07-02-2013 01:31, Elaine Kuo escreveu:
> Hello,
>
> I drew a plot of weight and height of people and fitted it with a
> polynominal regression x^2.
> (using curve())
>
> Now I would like to draw the confidence interval line for the fitted curve.
> Please kindly advise the code for the purpose.
> Thank you.
>
> Elaine
>
> 	[[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.
>



More information about the R-help mailing list