我想知道替代参数化在EvaStats中的表现 包(基于AM,GM,log10)等;我试过log10;但失败了!帮助
x=c(1151, 453, 1530, 2852, 1382)
meanx=mean(x);sdx=sd(x); cvx=sd/mean;
meanx; sdx; cvx
[1] 1473.6; [1] 874.2501; [1] 0.5932751
y1=log(x) # log(e) base
mean1=mean(y1);sd1=sd(y1); cv1=sd1/mean1;
mean1; sd1; cv1;
[1] 7.136873; [1] 0.6648726; [1] 0.09316022
现在对数正态分布(替代参数化);
library(EnvStats)
(p=seq(0.1,1,0.1));
qlnormAlt(p, mean =meanx, cv=cvx)
P [X≤x] ==> [1] 626.9803 798.3150 950.2311 1102.7414 1267.3461 1456.5211#1690.2899 [8] 2011.9454 2561.7490 Inf
qlnorm(p, meanlog = mean1, sdlog = sd1, lower.tail =TRUE, log.p = FALSE)
P [X≤x] ==> [1] 536.3594 718.5980 887.3269 1062.5527 1257.4901 1488.1910 1782.0729#[8] 2200.5088 2948.1747 Inf(excel中的结果相同)
答案 0 :(得分:1)
# For base R log-normal parameters
meanlog <- 0
sdlog <- 1
# convert to log-normal alt parameters
alt_cv <- sqrt(exp(sdlog^2) - 1)
alt_mean <- exp(meanlog + (sdlog^2)/2)
#Generate random variate
x <- rlnorm(10, meanlog = meanlog, sdlog = sdlog)
#The densities from ALT parameterization EnvStats
dlnormAlt(x, mean = alt_mean, cv = alt_cv, log = FALSE)
#0.07143345 0.02845393 0.65249008 0.55945034 0.12051190 0.51631108
#0.60456145 0.61928177 0.18041191 0.64513395
# From dlnorm
dlnorm(x, meanlog = meanlog, sdlog = sdlog, log = FALSE)
#0.07143345 0.02845393 0.65249008 0.55945034 0.12051190 0.51631108
#0.60456145 0.61928177 0.18041191 0.64513395
library(EnvStats)
# in log-normal alt
alt_mean <- 1.648721 # = exp(1/2)
alt_cv <- 1.310832 # = sqrt(exp(1) - 1)
# convert to base R log-normal
sdlog <- sqrt(log(1 + alt_cv^2))
meanlog <- log(alt_mean) - (sdlog^2)/2
# Check if this is correct by generating a sample and
# estimating density
#Generate random variate
x <- rlnormAlt(10, mean = alt_mean, cv = alt_cv)
#The densities from ALT parameterization EnvStats
dlnormAlt(x, mean = alt_mean, cv = alt_cv, log = FALSE)
#0.40210537 0.12318313 0.65370439 0.21540401 0.59956874 0.63914847
#0.05152114 0.04156760 0.48919495 0.05110028
# From dlnorm
dlnorm(x, meanlog = meanlog, sdlog = sdlog, log = FALSE)
#0.40210537 0.12318313 0.65370439 0.21540401 0.59956874 0.63914847
#0.05152114 0.04156760 0.48919495 0.05110028