--- title: "Fitting Models" author: "Prof. Eric A. Suess" format: html: self-contained: true --- ## Fitting Models Random sample from the normal distribution, estimate the parameters simulated sample ```{r} mu <- 43; sigma <- 5.97 # parameters n <- 300 x <- rnorm(n, mu, sigma) hist(x, probability = TRUE) ``` Estimate the parameters with x.bar and sd ```{r} mu.hat <- mean(x); mu.hat sigma.hat <- sd(x); sigma.hat ``` Plot the fitted model on the histogram ```{r} hist(x, probability = TRUE) curve(dnorm(x, mu.hat, sigma.hat), add=T) ``` Random sample from the exponential distribution, estimate the parameters simulated sample ```{r} lambda <- 11.34 # parameter n <- 30 x <- rexp(n, rate = lambda) hist(x, probability = TRUE) ``` Estimate the parameters with x.bar ```{r} lambda.hat = 1/mean(x); lambda.hat ``` Plot the fitted model on the histogram ```{r} 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?