This is a question about R, isn't it? I don't see panel.mathdensity
in core S+.
One way to do this is to write a panel.betadensity function that
estimates the distributions parameters from x and passes them
to panel.mathdensity. The following uses the method-of-moments
estimator because it is simple, but you can replace it with your
favorite.
panel.betadensity <- function (x, ...)
{
# method of moments estimator
xm <- mean(x) ; s2 <- var(x)
p <- xm * ( xm * (1.0 - xm)/s2 - 1.0)
q <- (1.0 - xm) * ( xm * (1.0 - xm) / s2 - 1.0)
# cat("p=",p, "; q=", q, "\n")
panel.mathdensity(dmath=dbeta, args=list(p,q), ...)
}
To test it:
d<-data.frame(group=rep(c("One","Two"),c(35,65)))
d$data <- c(rbeta(35,.2,.9), rbeta(65,2,7))
histogram(data=d, type="density", ~data|group,
panel=function(...){panel.histogram(...);panel.betadensity(...)})
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: s-news-owner@lists.biostat.wustl.edu
> [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Karin
> Sent: Monday, May 04, 2009 2:01 AM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] panel function mathdensity: How to get the
> parameters into that??
>
>
> Hello,
>
> I am looking for a hint in the following:
>
> I have observations on 'ydata' (relative duration) for
> several muscles (MUSCLE) and during several activities
> (ACT_2). Now I want to plot histograms of
> ydata with a panel function for each muscle and activity.
> Next to the histogram I want to plot the estimated beta
> distribution for that panel with panel.mathdensity. But how
> can I get the parameters for the beta distribution per panel
> into the panelfunction (shape1 and shape2)
> ?
>
> histogram( ~ ydata | MUSCLE*ACT_2,data=temp2,xlab="Relative
> duration", type = "density",
> panel = function(x, ...) {
> panel.histogram(x, ...)
> panel.mathdensity(dmath = dbeta, col = "black",
> args = list(shape1=??,shape2=???? )))
> } )
>
> Thanks in advance,
>
> Karin Groothuis
>
>
>
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|