Hi I have a dataset of absolute growth rates g ranging from close to 0 to around whatever of which I want to calculate a pdf. If I use density(g) the pdf will extend to below 0 so I logtransform g and do d <- density(log(g)). Now I would like to transform this pdf back, i.e. d$x <- exp(d$x) but what do I have to do with d$y? (below is a small example) Thanks for your help, Rainer g <- exp(rnorm(100)) ## Just to generate the example data d <- density(log(g)) dx <- d$x dp <- d$y sum(c(0, (diff(dx))) * dp) ## this is equal to one plot(dx, dp) dx2 <- exp(dx) dp2 <- ??????? ## what should I do here? plot(dx2, dp2) ## what should I do here? sum(c(0, (diff(exp(dx2)))) * dp2) ## this should be one sum( c(0, (diff(dx2))) * ( dp1 / c(1, (diff(exp(dx2)))) * c(0, (diff(dx1)))) ) ##This is obviously also one, but can I use this to define my dp2? i.e. dp2 <- dp1 / c(1, (diff(exp(dx2)))) * c(0, (diff(dx1)))) ###????
I think you need:
dx2 <- exp(dx)
dp2 <- dp / dx2
sum(c(0, diff(dx2)) * dp2)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Rainer M Krug" <R.M.Krug at gmail.com>
To: "r-help" <r-help at stat.math.ethz.ch>
Sent: Wednesday, January 16, 2008 10:34 AM
Subject: [R] Question concerning pdfs
> Hi
>
> I have a dataset of absolute growth rates g ranging from close to 0
> to
> around whatever of which I want to calculate a pdf.
> If I use density(g) the pdf will extend to below 0 so I logtransform
> g
> and do d <- density(log(g)).
> Now I would like to transform this pdf back, i.e. d$x <-
> exp(d$x) but what do I have to do with d$y?
>
> (below is a small example)
>
> Thanks for your help,
>
> Rainer
>
>
> g <- exp(rnorm(100)) ## Just to generate the example data
>
> d <- density(log(g))
> dx <- d$x
> dp <- d$y
>
> sum(c(0, (diff(dx))) * dp) ## this is equal to one
> plot(dx, dp)
>
> dx2 <- exp(dx)
> dp2 <- ??????? ## what should I do here?
>
> plot(dx2, dp2) ## what should I do here?
> sum(c(0, (diff(exp(dx2)))) * dp2) ## this should be one
>
>
> sum( c(0, (diff(dx2))) * ( dp1 / c(1, (diff(exp(dx2)))) * c(0,
> (diff(dx1)))) ) ##This is obviously also one, but can
> I
> use this to define my dp2? i.e.
>
> dp2 <- dp1 / c(1, (diff(exp(dx2)))) * c(0, (diff(dx1)))) ###????
>
> ______________________________________________
> 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
You may want to look at the logspline package. It is another way of estimating densities and allows you to specify boundries on the domain of x. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Rainer M Krug > Sent: Wednesday, January 16, 2008 2:35 AM > To: r-help > Subject: [R] Question concerning pdfs > > Hi > > I have a dataset of absolute growth rates g ranging from > close to 0 to around whatever of which I want to calculate a pdf. > If I use density(g) the pdf will extend to below 0 so I > logtransform g and do d <- density(log(g)). > Now I would like to transform this pdf back, i.e. d$x <- > exp(d$x) but what do I have to do with d$y? > > (below is a small example) > > Thanks for your help, > > Rainer > > > g <- exp(rnorm(100)) ## Just to generate the example data > > d <- density(log(g)) > dx <- d$x > dp <- d$y > > sum(c(0, (diff(dx))) * dp) ## this is equal to one plot(dx, dp) > > dx2 <- exp(dx) > dp2 <- ??????? ## what should I do here? > > plot(dx2, dp2) ## what should I do here? > sum(c(0, (diff(exp(dx2)))) * dp2) ## this should be one > > > sum( c(0, (diff(dx2))) * ( dp1 / c(1, (diff(exp(dx2)))) * c(0, > (diff(dx1)))) ) ##This is obviously also one, but can I > use this to define my dp2? i.e. > > dp2 <- dp1 / c(1, (diff(exp(dx2)))) * c(0, (diff(dx1)))) ###???? > > ______________________________________________ > 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. >