Search code examples
rstatisticsepochnormal-distribution

rtruncnorm function in R generates same observations


I am trying to use truncated normal distribution function in R to generate numbers between upper and lower bounds. This is the statement I am using:

rtruncnorm(4,1494396000,1494397800, 6360,2640)

4 - Number of observations i need, 1494396000 - Epoch time (actual time: 2017-05-10 02:00:00), 1494397800 - Epoch time (actual time: 2017-05-10 02:30:00), 6360 - mean 106 mins (106*60 = 6360 seconds), 2640 - SD 44 mins (44*60 = 2640 seconds)

This should ideally give me 4 observations of epoch times between 02:00:00 and 02:30:00 on May 10 But the output I am getting is: 1494396000 1494396000 1494396000 1494396000 which is 2017-05-10 02:00:00

I can't understand why rtruncnorm is giving me 4 exactly same observations. I tried using rtnorm function from msm package and the result is the same.

A nudge in the right direction would be greatly appreciated


Solution

  • The lower truncation limit of 1,494,396,000 is 566,057 standard deviations above the mean of 6,360. It looks like when you specify a mean that results in all the simulated values being below the lower truncation limit, the function just returns the lower truncation limit for every value. I think you must have meant to specify a mean somewhere between your truncation limits.

    library(truncnorm)
    
    rr = c(1494396000, 1494397800)
    
    hist(rtruncnorm(10000, 1494396000, 1494397800, 1494396000, 500), 
         breaks=seq(rr[1],rr[2], length=40), xlim=rr, main="Mean=1494396000", xlab="")
    
    hist(rtruncnorm(10000, 1494396000, 1494397800, 6360, 500), 
         breaks=seq(rr[1],rr[2], length=40), xlim=rr, main="Mean=6360", xlab="")
    

    enter image description here