[R] Bug in truncdist package

dario.romare at accenture.com dario.romare at accenture.com
Thu Dec 3 11:03:32 CET 2015


library(truncdist)

When running the following code, the output from extrunc() and vartrunc() is correct:

# 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)
vartrunc("gamma",a=0,b=Inf,shape=a,rate=1/s)

However, changing the mean from 40 to 44:
m <- 44; v <- 9

and running the code again, the output is as follows:

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


________________________________

This message is for the designated recipient only and ma...{{dropped:16}}



More information about the R-help mailing list