truncdist包中的Bug

truncdist包中的Bug,r,R,运行以下代码时,extrunc()和vartrunc()的输出是正确的: library(truncdist) 你在问什么?你在问什么? # Mean and variance of Gamma distribution m <- 40; v <- 9 # Derive shape and scale parameters a <- m^2/v; s <- v/m # Checks: mean = shape * scale, variance = mean * sc

运行以下代码时,extrunc()和vartrunc()的输出是正确的:

library(truncdist)

你在问什么?你在问什么?
# Mean and variance of Gamma distribution
m <- 40; v <- 9

# Derive shape and scale parameters
a <- m^2/v; s <- v/m
# Checks: mean = shape * scale, variance = mean * scale^2
a*s; a*s^2
# Generate 1M random samples from Gamma distribution
x <- rgamma(10^6,shape=a,rate=1/s)
# Checks
mean(x); var(x)
# Mean and variance of corresponding theoretical Gamma
extrunc("gamma",a=0,b=Inf,shape=a,rate=1/s)  # = 40
vartrunc("gamma",a=0,b=Inf,shape=a,rate=1/s) # = 9
extrunc("gamma",a=0,b=Inf,shape=a,rate=1/s)  # = 3.8101e-06
vartrunc("gamma",a=0,b=Inf,shape=a,rate=1/s) # = 1945