pf2pf {lazy.stat} | R Documentation |
(This is a Beta Version.)
pf2pf( x, pf, xout, maxx = NULL, maxx2 = NULL, normalize = 1, print = 0, plot = 0 )
x |
A vector at which pf is defined |
pf |
A vector of probability function which sums to unity. |
xout |
A vector of new values at which pf will be calculated. |
maxx |
max value of X or NULL. |
maxx2 |
max value of Xout or NULL. |
print |
= 1 to print the result |
plot |
= 1 to plot the result |
This function assumes that the random variable X is continuous and that the probability density function, pf, at x is normalized so that sum(pf)=1. Therefore, it is called pf, not pdf. Now, we wish to calculate the normalized pdf, pf2, at xout such that sum(pf2)=1. In order to do so, we proceed as follows:
0. adjust the value of x and xout to x2 and xout2 where x2 = x + half length of the interval x[i] and x[i+1], i < n, x2 = x + ???????????????????????????????????????? 1. calculate cdf from pf. 2. interpolate (x2,cdf) to get (xout2,cdf2). 3. calculate pf2 at xout using cdf2pf. 4. normalize pf2 so that is sums to unity.
The tail probabilities are defined so that
pf(1) = Pr( X < x[1]+dd ), pf(n) = Pr( X > x[n]-dd )
A vector containing pf at xout.
# discretized standard normal set.seed(1701) x <- seq(-3,3,len=11) pf <- dnorm(x) pf <- pf/sum(pf) cdf <- cumsum(pf) pf2 <- cdf2pf( x, cdf, print=1, plot=1 ) stat <- unlist(mandd( x, pf2 )[c("mean","var","std")]) Print(stat, fmt="10.5") # calculate pf2 at new xout from (x,pf) xout <- seq(-3,3,len=15) pf2 <- pf2pf( x, pf, xout, print=1, plot=3 ) stat <- unlist(mandd( xout, pf2 )[c("mean","var","std")]) Print(stat, fmt="10.5") # calculate pf2 at new xout from (x,pf): Large tail probabilities. xout <- seq(-2, 2, len=21) pf2 <- pf2pf( x, pf, xout, print=1, plot=3 ) stat <- unlist(mandd( xout, pf2 )[c("mean","var","std")]) Print(stat, fmt="10.5") # Change of Variable # standard normal to log normal x <- seq(-3,3,len=121) pf <- dnorm(x) pf <- pf/sum(pf) # log normal at equal interval: log(x2) ~ N( 0, 1 ) x2 <- exp(x) xout <- c( 0.05, seq(0.1,20,0.1) ) pf2 <- pf2pf( x2, pf, xout, plot=2 )