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}}

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to