confidence interval as shaded band (lme)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

confidence interval as shaded band (lme)

benjamin_jarrett
Hi all,

I’m trying to plot confidence intervals for the fitted values I get with my lme model in R.

Is there any way I can plot this in the form of a shaded band, like the output of geom_smooth() in ggplot2 package. ggplot2 seems to use only lm, glm, gam, loess and rlm as smoothing methods.

Any advice on the functions I should use to accomplish this will be very helpful.

Thank you very much.

Ben
Reply | Threaded
Open this post in threaded view
|

Re: confidence interval as shaded band (lme)

Michael Weylandt
I don't know lme models very well, but if you have standard errors for your
values, this shouldn't be too hard (as a last resort) using polygon()

For example

x = 1:10
y = x^2
y.Err = 2*x
y.Up = y + y.Err; y.Dn =y-y.Err

# This graph is actually quite ugly so don't copy the formatting....
plot(x,y,type="n")
polygon(c(x,rev(x)),c(y.Up,rev(y.Dn)),col="grey",border="red")
# Use the rev commands so the border moves logically around the shaded area
lines(x,y,type="b",lwd=3) # put the means back on top of the polygon

Still, this is a little brute force and I'd imagine that someone else will
shortly let you know how R can already do automatically.

Michael Weylandt

On Mon, Aug 8, 2011 at 1:07 PM, bjmjarrett <[hidden email]> wrote:

> Hi all,
>
> I’m trying to plot confidence intervals for the fitted values I get with my
> lme model in R.
>
> Is there any way I can plot this in the form of a shaded band, like the
> output of geom_smooth() in ggplot2 package. ggplot2 seems to use only lm,
> glm, gam, loess and rlm as smoothing methods.
>
> Any advice on the functions I should use to accomplish this will be very
> helpful.
>
> Thank you very much.
>
> Ben
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/confidence-interval-as-shaded-band-lme-tp3727645p3727645.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: confidence interval as shaded band (lme)

djmuseR
In reply to this post by benjamin_jarrett
Hi:

On Mon, Aug 8, 2011 at 10:07 AM, bjmjarrett <[hidden email]> wrote:
> Hi all,
>
> I’m trying to plot confidence intervals for the fitted values I get with my
> lme model in R.

Which fitted values? The ones conditional on the random effects or the
ones averaged over the random effects? The standard errors of the two
sets of predictions are not the same.
>
> Is there any way I can plot this in the form of a shaded band, like the
> output of geom_smooth() in ggplot2 package. ggplot2 seems to use only lm,
> glm, gam, loess and rlm as smoothing methods.

You can fake it with geom_ribbon(), but it would be convenient to have
the endpoints of the CIs in a data frame you could input into ggplot2.

HTH,
Dennis

>
> Any advice on the functions I should use to accomplish this will be very
> helpful.
>
> Thank you very much.
>
> Ben
>
> --
> View this message in context: http://r.789695.n4.nabble.com/confidence-interval-as-shaded-band-lme-tp3727645p3727645.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: confidence interval as shaded band (lme)

Bert Gunter
Would someone tell me how they propose to go from "standard errors" to
confidence intervals*. I suspect Doug Bates would probably like to
know, also, as he has expended a lot of effort on this over the years,
I believe.  :-)

-- Bert

* Note   +/- 2 std errors is almost certainly not the right answer --
how far wrong it is ... that's the question.


Cheers,
Bert

On Mon, Aug 8, 2011 at 1:07 PM, Dennis Murphy <[hidden email]> wrote:

> Hi:
>
> On Mon, Aug 8, 2011 at 10:07 AM, bjmjarrett <[hidden email]> wrote:
>> Hi all,
>>
>> I’m trying to plot confidence intervals for the fitted values I get with my
>> lme model in R.
>
> Which fitted values? The ones conditional on the random effects or the
> ones averaged over the random effects? The standard errors of the two
> sets of predictions are not the same.
>>
>> Is there any way I can plot this in the form of a shaded band, like the
>> output of geom_smooth() in ggplot2 package. ggplot2 seems to use only lm,
>> glm, gam, loess and rlm as smoothing methods.
>
> You can fake it with geom_ribbon(), but it would be convenient to have
> the endpoints of the CIs in a data frame you could input into ggplot2.
>
> HTH,
> Dennis
>>
>> Any advice on the functions I should use to accomplish this will be very
>> helpful.
>>
>> Thank you very much.
>>
>> Ben
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/confidence-interval-as-shaded-band-lme-tp3727645p3727645.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.
>



--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

______________________________________________
[hidden email] 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.