[R] plotting confidence intervals for polynomial models? (was Re: ordinary polynomial coefficients from orthogonal polynomials?)
James Salsman
james at bovik.org
Tue Jun 14 17:08:18 CEST 2005
What I really want now are the 95% confidence intervals that I
mistakenly thought that linesHyperb.lm() would provide:
> pm <- lm(billions ~ I(decade) + I(decade^2) + I(decade^3))
> library(sfsmisc)
> linesHyperb.lm(pm)
Error in "names<-.default"(`*tmp*`, value = c("I(decade)",
"I(decade^2)", :
names attribute [3] must be the same length as the vector [1]
> pm <- lm(billions ~ poly(decade, 3))
> linesHyperb.lm(pm)
Warning message:
'newdata' had 100 rows but variable(s) found have 5 rows
Shouldn't curve(predict(...), add=TRUE) be able to plot confidence
interval bands?
Prof Brian Ripley wrote:
> Why do `people' need `to deal with' these, anyway. We have machines to
> do that.
Getting a 0.98 adjusted R^2 on the first try, compels me to
try to publish the fitted formula.
>>>>> decade <- c(1950, 1960, 1970, 1980, 1990)
>>>>> billions <- c(3.5, 5, 7.5, 13, 40)
>>>>> # source: http://www.ipcc.ch/present/graphics/2001syr/large/08.17.jpg
>>>>>
>>>>> pm <- lm(billions ~ poly(decade, 3))
>>>>>
>>>>> plot(decade, billions, xlim=c(1950,2050), ylim=c(0,1000),
>>>> main="average yearly inflation-adjusted dollar cost of extreme weather
>>>> events worldwide")
>>>>> curve(predict(pm, data.frame(decade=x)), add=TRUE)
>>>>> # output: http://www.bovik.org/storms.gif
>>>>>
>>>>> summary(pm)
>>>>
>>>> Call:
>>>> lm(formula = billions ~ poly(decade, 3))
>>>>
>>>> Residuals:
>>>> 1 2 3 4 5
>>>> 0.2357 -0.9429 1.4143 -0.9429 0.2357
>>>>
>>>> Coefficients:
>>>> Estimate Std. Error t value Pr(>|t|)
>>>> (Intercept) 13.800 0.882 15.647 0.0406 *
>>>> poly(decade, 3)1 25.614 1.972 12.988 0.0489 *
>>>> poly(decade, 3)2 14.432 1.972 7.318 0.0865 .
>>>> poly(decade, 3)3 6.483 1.972 3.287 0.1880
>>>> ---
>>>> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
>>>>
>>>> Residual standard error: 1.972 on 1 degrees of freedom
>>>> Multiple R-Squared: 0.9957, Adjusted R-squared: 0.9829
>>>> F-statistic: 77.68 on 3 and 1 DF, p-value: 0.08317
More information about the R-help
mailing list