Question

In: Math

(R programming) Generate 50 samples from a Poisson distribution with lambda to be 2 and define...

(R programming)

Generate 50 samples from a Poisson distribution with lambda to be 2 and define the log likelihood function

Use optimization to find the maximum likelihood estimator of lambda. Repeat for 100 times using forloop. You will need to save the results of the estimated values of lambda.

Solutions

Expert Solution

R-Code for log likelihood function:

set.seed(123)
lambda = 2
i = 1
lambda_est = rep(0,100)
log_likely = rep(0,100)
for (i in 1:100)
{
sample = rpois(50, lambda = 2)
negloglike = function(lam)
{
length(sample) * lam - sum(sample) * log(lam) + sum(log(factorial(sample)))
}
log_likely[i] = negloglike(lambda)
lambda_est[i] = nlm(negloglike,p=c(0.5), hessian = F)$estimate
}
log_likely
87.80200 82.04497 86.52106 76.66969 82.42672 87.34329 85.94124 89.22911 86.45207 86.59802 85.68173 87.05560 87.40895 81.35182 90.69237 76.73423 86.36246 85.15848 85.78709 82.37347 76.26423 82.79136 80.59414 84.75302 90.50559 81.69275 78.68459 82.43801 85.09395 99.14966 83.18440 83.24894 89.55293 84.21402 94.78671 86.92653 85.56395 85.78709 81.05172 78.97228 90.81835 88.78283 80.99960 90.49430 86.36246 93.50132 80.31775 86.48024 79.62460 81.98043 83.41997 79.15460 85.88800 90.21791 88.16664 82.73812 82.80378 86.25710 81.18192 86.95024 84.40080 86.88571 84.68848 81.28728 87.44532 86.30921 78.76155 82.26811 85.99781 80.76404 85.49941 86.28217 78.56681 86.25710 90.06376 96.06765 84.68848 86.30589 92.36634 89.12375 87.73746 83.30219 83.12783 82.55579 74.94247 78.52599 87.83836 82.09821 89.42386 77.54516 78.93145 83.87755 86.89813 79.25996 89.57801 85.27627 79.89986 84.31938 81.98043 85.85163

lambda_est
2.239999 1.799999 2.139999 1.979999 2.059999 1.799999 1.959999 2.099999 2.039999 1.959999 1.920000 2.159999 2.059999 1.920000 2.139999 1.739999 1.839999 1.999999 2.099999 1.920000 1.819999 1.900000 1.979999 1.859999 1.999999 1.999999 1.839999 1.659999 2.139999 2.459999 2.039999 1.719999 2.119998 1.920000 2.179999 2.219999 2.159999 2.119998 1.799999 1.839999 2.139999 1.939999 1.999999 2.159999 1.880000 2.179999 1.880000 2.099999 1.659999 1.900000 2.259999 1.799999 1.900000 1.999999 2.119998 1.920000 2.139999 1.880000 2.059999 1.900000 2.039999 2.139999 1.979999 1.799999 2.179999 1.739999 1.920000 2.039999 1.979999 1.859999 2.059999 2.339999 1.939999 1.999999 2.059999 2.139999 2.059999 1.920000 2.039999 2.119998 2.279999 1.999999 2.079999 1.699999 1.699999 1.759999 1.939999 2.079999 2.119998 1.819999 1.719999 1.959999 2.159999 1.799999 2.259999 2.159999 1.479999 1.799999 2.019999 1.939999


Related Solutions

In r-studio, given X=rpois(200,2). Generate a poisson probability histogram with lambda=2 and a relative frequency histogram...
In r-studio, given X=rpois(200,2). Generate a poisson probability histogram with lambda=2 and a relative frequency histogram of the sample on the same graph-------- //answer this only if youre familiar with R studio and know how to using it. not handwritten//
r programming generate 100 samples of size n= 5 from a normal random variable with u=2,...
r programming generate 100 samples of size n= 5 from a normal random variable with u=2, o= 3 in r
Compute E(S^2) and V(S^2) if Xi follows the Poisson distribution with \lambda.
Compute E(S^2) and V(S^2) if Xi follows the Poisson distribution with \lambda.
a. Generate samples of size 25, 50, 100 from a normal distribution. Construct probability plots. Do...
a. Generate samples of size 25, 50, 100 from a normal distribution. Construct probability plots. Do this several times to get an idea of how probability plots behave when the underlying distribution is really normal. b. Repeat part (a) for a chi-square distribution with 10 df I am required to use the R statistical program and I do not understand how to use it to solve this problem. If you could please show me the R Stats needed to solve...
3. (3 pt) Use R functions to generate 1000 random samples from t-distribution with 15 degrees...
3. (3 pt) Use R functions to generate 1000 random samples from t-distribution with 15 degrees of freedom. Make a histogram with the samples showing the relative frequencies. Then overlay a probability density plot over this histogram.
2. Use MINITAB to generate 10,000 observations from a binomial distribution with n = 50 trials...
2. Use MINITAB to generate 10,000 observations from a binomial distribution with n = 50 trials and probability of success p = 0.02 . Create a histogram of the 10,000 observations. Comment on the shape of the distribution. Why does it makes sense for the histogram to have this shape? 3. Use MINITAB to generate 10,000 observations from a binomial distribution with n = 1000 trials and probability of success p = 0.02. Create a histogram of the 10,000 observations....
Consider a Poisson probability distribution with lambda equals5.3 . Determine the following probabilities. ​a) exactly 5...
Consider a Poisson probability distribution with lambda equals5.3 . Determine the following probabilities. ​a) exactly 5 occurrences ​b) more than 6 occurrences ​c) 3 or fewer occurrences
Use R and perform following: Generate 1000 observations from an exponential distribution with mean 10. Generate...
Use R and perform following: Generate 1000 observations from an exponential distribution with mean 10. Generate 1000 observations from a central t-distribution with 8 degree of freedom. Make a qqplot of observations in problem 1 versus quantiles generated from a t-distribution with 8 degree of freedom. Can the t distribution be used to approximate data in part 1?Submit the plot. Repeat above part but submit a qqplot of the observations in 1 versus quantiles from an exponential with mean 1....
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution...
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution between -0.5 and 0.5, and find the mean of these 10 numbers. Consider this mean to be the ‘result’ of this procedure. b) Repeat this 10 times and calculate the mean and variance of your 10 results. Is the distance of the mean from 0 about what you would expect? Why? c) Now repeat it 100 times and calculate the mean and variance. Is...
****MUST BE FAMILIAR WITH R STUDIO PROGRAMMING***** Random samples of resting heart rates are taken from...
****MUST BE FAMILIAR WITH R STUDIO PROGRAMMING***** Random samples of resting heart rates are taken from two groups. Population 1 exercises regularly, and population 2 does not. The data from these two samples (in beats per minute) are given below: Exercise group (sample from population 1): 62.4, 64.1, 66.8, 60.7, 68.2, 69.2, 64.9, 70.9, 67.7, 68, 58.5, 58.9, 64.7 No exercise group (sample from population 2): 79.3, 73.8, 75.3, 74.7, 76.9, 74.9, 73.2, 75.7, 75.2, 76.7, 78.7 Estimate the difference...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT