mu <- 43; sigma <- 5.97 # parameters
n <- 300
x <- rnorm(n, mu, sigma)
hist(x, probability = TRUE)Fitting Models
Fitting Models
R andom sample from the normal distribution, estimate the parameters
simulated sample
Estimate the parameters with x.bar and sd
mu.hat <- mean(x); mu.hat[1] 42.54465
sigma.hat <- sd(x); sigma.hat[1] 6.137992
Plot the fitted model on the histogram
hist(x, probability = TRUE)
curve(dnorm(x, mu.hat, sigma.hat), add=T)Random sample from the exponential distribution, estimate the parameters
simulated sample
lambda <- 11.34 # parameter
n <- 30
x <- rexp(n, rate = lambda)
hist(x, probability = TRUE)Estimate the parameters with x.bar
lambda.hat = 1/mean(x); lambda.hat[1] 9.726872
Plot the fitted model on the histogram
hist(x, probability = TRUE)
curve(dexp(x, rate = lambda.hat), add=T)Now suppose we want to fit the gamma distribution to a random sample how can we do this?
Can we use x.bar and the sd?
The big question is, how do we estimate parameters in models in general?