[R] CIs in predict?

Simon Blomberg blomsp at ozemail.com.au
Tue Jul 12 01:47:21 CEST 2005


At 08:40 AM 12/07/2005, Guy Forrester wrote:
>Dear All,
>
>
>I am trying to put some Confidence intervals on some regressions from a 
>linear model with no luck.  I can extract the fitted values using 
>'predict', but am having difficulty in getting at the confidence 
>intervals, or the standard errors.
>
>Any suggestions would be welcome
>
>Cheers
>
>Guy
>
>Using Version 2.1.0  (2005-04-18) on a PC
>
>
>
>
>vol.mod3 <- lm(log.volume~log.area*lake,data=vol)
>summary(vol.mod3)
>
>plot(c(1.3,2.5),c(-0.7,0.45),type="n",xlab="Log area",ylab="Log volume")
>
>areapred.a <- seq(min(vol$log.area[vol$lake=="a"]), 
>max(vol$log.area[vol$lake=="a"]), length=100)
>areapred.b <- seq(min(vol$log.area[vol$lake=="b"]), 
>max(vol$log.area[vol$lake=="b"]), length=100)
>
>
>preda <- predict(vol.mod3, 
>data.frame(log.area=areapred.a,interval="confidence" ,lake=rep("a",100)))

You have interval="confidence" inside your call to data.frame, not inside 
your call to predict. Hence you are creating a data frame with a variable 
called interval, with one level called confidence, and predict does not see 
interval="confidence" at all! See ?predict.lm.

HTH,

Simon.


>#This gives the fitted values as predicted, but no CIs
> > preda
>            1            2            3            4            5 
>    6            7            8            9
>-0.562577529 -0.553263576 -0.543949624 -0.534635671 -0.525321718 
>-0.516007765 -0.506693813 -0.497379860 -0.488065907
>           10           11           12           13           14 
>   15           16           17           18
>-0.478751955 -0.469438002 -0.460124049 -0.450810097 -0.441496144 
>-0.432182191 -0.422868239 -0.413554286 -0.404240333
>           19           20           21           22           23 
>   24           25           26           27
>-0.394926380 -0.385612428 -0.376298475 ETC ETC
>
>#As does this, but with no SEs
> > preda <- predict(vol.mod3, data.frame(log.area=areapred.a,se.fit=T 
> ,lake=rep("a",100)))
> > preda
>            1            2            3            4            5 
>    6            7            8            9           10
>-0.562577529 -0.553263576 -0.543949624 -0.534635671 -0.525321718 
>-0.516007765 -0.506693813 -0.497379860 -0.488065907 -0.478751955
>           11           12           13           14           15 
>   16           17           18           19           20
>-0.469438002 -0.460124049 -0.450810097 ETC ETC
>
>
>
>
>--------------------------------------------------------
>Guy J Forrester
>Biometrician
>Manaaki Whenua - Landcare Research
>PO Box 69, Lincoln, New Zealand.
>Tel. +64 3 325 6701 x3738
>Fax +64 3 325 2418
>E-mail ForresterG at LandcareResearch.co.nz
>www.LandcareResearch.co.nz
>
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>WARNING: This email and any attachments may be confidential ...{{dropped}}
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list