Fit distribution from a truncated data

72 views Asked by At

I'm trying to find the parameters of a distribution which fits to truncated data.

There's a similar unanswered post here: Fit a statistical distribution to truncated data

     # Generate truncated data, x ~ N(3, 1) and x <= 2

     N <- 10000
     trunc <- rnorm(N, mean = 3, sd = 1)
     trunc <- trunc[which(trunc <= 2)]
     
     print(fitdistr(trunc, densfun = 'normal'))
     >     mean           sd     
     >  1.479185403   0.426895843 
     > (0.010695819) (0.007563086) # does not return mean 3 and sd 1

The above code generated an illustration with x drawn from N(3, 1) but truncated above 2. Can I recover the original normal distribution with fitdistr or fitdistrplus?

1

There are 1 answers

0
Friede On

Generate truncated data, x ~ N(3, 1) and x <= 2

That is the other way round. {extraDistr} is made for this. For details look at the documentation, e.g. ?rtnorm.

set.seed(1L)
library(extraDistr)
x <- rtnorm(1e5, 3L, 1L, b = 2L)
hist(x, 100, freq = FALSE)

I'm trying to find the parameters of a distribution which fits to truncated data

Then you could use this answer from @jdblood94.

> tnorm.mle(x = x, a = -Inf, b = 2L)
       mu     sigma 
2.9575804 0.9877055