Bonjour,
Il y a plusieurs façons de le faire en R. Sans entrer dans les détails de ce que fait le code montré (le mélange des distributions gaussiennes et uniformes me paraît étrange vu l'énoncé), je propose une autre manière : le package fitdistrplus.
1 2 3
| > library("fitdistrplus")
> x <- runif(100, -3, 3)
> fitdist(data = x, distr = "unif", method = "mle") |
Fitting of the distribution ' unif ' by maximum likelihood
Parameters:
estimate Std. Error
min -2.977003 NA
max 2.945257 NA
> fitdist(data = x, distr = "unif", method = "mme")
Fitting of the distribution ' unif ' by matching moments
Parameters:
estimate
1 -3.100314
2 2.840496
> fitdist(data = x, distr = "unif", method = "qme", probs = c(1/3, 2/3))
Fitting of the distribution ' unif ' by matching quantiles
Parameters:
estimate
min -3.347531
max 2.995502
> fitdist(data = x, distr = "unif", method = "mge", gof = "CvM")
Fitting of the distribution ' unif ' by maximum goodness-of-fit
Parameters:
estimate
min -3.093458
max 2.823104
Fitting of the distribution ' unif ' by maximum likelihood suffit amplement à répondre à l'énoncé, je donne les autres approches pour susciter la curiosité. Voir la documentation pour les détails entre les différentes approches d'estimation des paramètres.
Partager