Question

Please answer this question with RStudio.

4. In this problem, you will illustrate the idea of resampling and sampling distributions. A ganma distribution with shape k and scale θ has density exp(-v/0) Assume shape k = 2 and scale θ = 3 (a) Use the function dgamma in R to evaluate the density for a range of values between 0 and 20. Produce a plot of the density (b) The (true) mean and variance of the gamma distribution are simple functions of the shape and scale parameters. Use the internet (Wikipedia is fine) to find the true mean μ, variance σ2, and standard deviation σ of the distribution described in (a) (c) Assume we take a sample of size n- 12 where X, are iid random variables with gamma distributions with shape k = 2 and scale θ = 3 and we calculate X = 1/12 ΣΙ, x, . 1s X random? Explain (d) Give the true mean ,48, variance σ, and standard deviation ơX, of X in (c) Test statistics are usually standardized so that standard tables can be used. The distribution of interest is the distribution of X. To standardize, one subtracts off the mean, and divides by the standard deviation. The trick is, usually the true mean and true standard deviation arent known. It turns out that in a test for means, the fact that the true mean is unknown is not a problem because we hypothesize the true mean with the null hypothesis. However, the fact that the standard deviation is unknown does make a difference, as we illustrate below. (e) Use rgamma to generate a sample of sizen 12 from a gamma distribution with shape k-2 and scale θ-3. Calculate the sample mean m. Suppose our null hypothesis is Ho : μ-6. Calculate the test statistic Z-ms- m .. Note: This test statistic assumes the true standard deviation is known. Use a for-loop to repeatedly calculate the test statistic and store these values. Plot a histogram of the test statistics, and use dnorm to overlay a standard normal density. You may want to adjust the histogram settings, look at the help page: ?hist, and you will want to set freqF to compare with the normal density. Does the distribution of this test statistic appear to be well approximated by a standard normal? (f) Repeat (e), but now using the test statistic T = -2, where 8 is the sample standard deviation. Does the distribution of this test statistic appear to be well approximated by a standard normal? Use R to draw the density curve of a more appropriate distribution

0 0
Add a comment Improve this question Transcribed image text
Answer #1

R code with comments (all statements starting with # are comments)

#set the parameters of gamma distribution
k<-2
theta<-3
#part a)
#set the values of x
x<-seq(0,20,length=100)
#get the density of x
p<-dgamma(x,shape=k,scale=theta)
#plot
plot(x,p,type="l",ylab="density",main=bquote("Density of gamma distribution with k=2,"*theta*"=3"))

#get this plot

Density of gamma distribution with k-2,0-3 ON 10 15 20 0

b) The expected value (true mean) of X is

mu=E(X)=k heta=2 imes 3=6

the variance of X is

sigma^2=Var(X)=k heta^2=2 imes 3^2=18

#part b)
#expected value is
mu<-k*theta
sigma2<-k*theta^2
sprintf('The true mean of X is %.4f',mu)
sprintf('The true variance of X is %.4f',sigma2)

#get this poutput

> 3printf (The true mean of X 13·4f,mu) [1] The true mean of X is 6.0000 > sprintf (The true variance f X is % .4 f, sigma2 ) [1] The true variance of X is 18.0000

c) Each sample of size 12 is a draw from Gamma distribution and they are different.

Since X_is are random variables, the sum

12 is also a random variable.

If we divide this sum by n, the average that we get of these X_is is also random.

Hence 12 is a random variable.

d) the true mean of ar{X} is

mu_{ar{X}}=mu=6

The true variance of ar{X} is

=1.5 12 =ー=

The true standard deviation of ar{X} is

0% = V1.5 = 1.225

R code

#part d)
#set the sample size
n<-12
#get the true mean of sample mean
muxbar<-mu
#get the true variance of sample mean
sigma2xbar<-sigma2/n
#get the true standard deviation of sample mean
sigmaxbar<-sqrt(sigma2xbar)

sprintf('The true mean of sample mean is %.4f',muxbar)
sprintf('The true variance of sample mean is %.4f',sigma2xbar)
sprintf('The true standard deviation of sample mean is %.4f',sigmaxbar)

#get this output

> sprintf(The true mean of sample mean is . 4f,muxbar) 1 The true mean of sample mean is 6.0000 > sprintf (The true variance of sample mean is·4f,sigma2xbar) 1 The true variance of sample mean is 1.5000 > sprintf (The true standard deviation of sample mean is % .4 f, sigmaxbar) 1 The true standard deviation of sample mean is 1.2247

e) R code

#part e)
#set the random seed
set.seed(123)
#set the sample size
n<-12
#set the number of repetition
r<-10000
#intialize the variable to store the z values
z<-numeric(r)
for (i in 1:r) {
    x<-rgamma(n,shape=k,scale=theta)
   #get the sample mean m
   m<-mean(x)
   #calculate the test statistics
   z[i]<-(m-6)/sigmaxbar
}
#plot the histogram of z
hist(z,breaks=50,freq=FALSE,xlab="Test statistics (z)",main="Histogram of the test statistics")
#add dnorm
curve(dnorm(x),from=min(z),to=max(z),add=TRUE,col="red")

#get this plot

Histogram of the test statistics CN -2 0 2 4 6 Test statistics (z)

The distribution of the test statistics is reasonably well approximated by a normal distribution.

f) Using sample standard deviation

#part f)
#set the random seed
set.seed(123)
#set the sample size
n<-12
#set the number of repeatition
r<-10000
#intialize the variable to store the z values
t<-numeric(r)
for (i in 1:r) {
    x<-rgamma(n,shape=k,scale=theta)
   #get the sample mean m
   m<-mean(x)
   #get the sample standard deviation
   s<-sd(x)
   #calculate the test statistics
   t[i]<-(m-6)/(s/sqrt(n))
}
#plot the histogram of t
hist(t,breaks=50,freq=FALSE,xlab="Test statistics (t)",main="Histogram of the test statistics",ylim=c(0,0.4))
#add dnorm
curve(dnorm(x),from=min(t),to=max(t),add=TRUE,col="red")
#add dt
curve(dt(x,df=n-1),from=min(t),to=max(t),add=TRUE,col="blue")
legend("topleft",c("test statistics","standard normal","standard t"),lty=1,col=c("black","red","blue"))

#get this plot

Histogram of the test statistics o test statistics standard normal standardt -8 -6 -4 -2 2 4 Test statistics (t)

t distribution with its thicket tail seems to be a better fit than standard normal, particularly for the left tail.

Add a comment
Know the answer?
Add Answer to:
Please answer this question with RStudio. 4. In this problem, you will illustrate the idea of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A mixture of pulverized fuel ash and Portland cement to be used for grouting should have a compressive strength of more than 1300 KN/m2. The mixture will not be used unless experimental evidence indi...

    A mixture of pulverized fuel ash and Portland cement to be used for grouting should have a compressive strength of more than 1300 KN/m2. The mixture will not be used unless experimental evidence indicates conclusively that the strength specification has been met. Suppose compressive strength for specimens of this mixture is normally distributed with σ-60. Let μ denote the true average compressive strength (a) What are the appropriate null and alternative hypotheses? Ho: μ < 1300 Hai μ-1300 Hu: μ-1300...

  • please answer correctly and answer all questions.. this is revision question... 7. Which of the following...

    please answer correctly and answer all questions.. this is revision question... 7. Which of the following is BEST graphical method for describing categorical data? A. Bar chart B. Histogram C.Box-plot D. Pareto chart 8. Which of the following is NOT property of the variance? A. It measures the amount of spread or variability of observation from mean B. Standard deviation is square root of variance C. Normally used for describing measure of dispersion during reporting research data D. It is...

  • A mixture of pulverized fuel ash and Portland cement to be used for grouting should have...

    A mixture of pulverized fuel ash and Portland cement to be used for grouting should have a compressive strength of more than 1300 KN/m2. The mixture will not be used unless experimental evidence indicates conclusively that the strength specification has been met. Suppose compressive strength for specimens of this mixture is normally distributed with σ-70. Let μ denote the true average compressive strength. a) What are the a null and altenative hypotheses? Ho: 1300 на: #1300 Ho:> 1300 hja: μ-1300...

  • 3. Testing a population mean The test statistic (Chapter 11) Aa Aa You conduct a hypothesis...

    3. Testing a population mean The test statistic (Chapter 11) Aa Aa You conduct a hypothesis test about a population mean u with the following null and alternative hypotheses: Ho: u-25.8 H1: <25.8 Suppose that the population standard deviation has a known value of a observations, which provides a sample mean of % 30.7. 17.8. You obtain a sample of n =62 Since the sample size large enough, you assume that the sample mean X follows a normal distribution. Let...

  • please answer correctly and answer all question.. this is revision question.. thanks.. 21. Which of the...

    please answer correctly and answer all question.. this is revision question.. thanks.. 21. Which of the following is FALSE regarding ANOVA test? A. The Kruskal-Wallis test is the non-parametric equivalent for one-way ANOVA test B. The independent variable in one-way ANOVA test should be a categorical variable The dependent variable in one-way ANOVA test should be a numerical variable (D.Doe-way ANOVA test cannot be applied to compare two means (comparison of two groups) 22. Which of the following is FALSE...

  • Univariate Gaussians or normal distributions have a simple representation in that they can be completely described...

    Univariate Gaussians or normal distributions have a simple representation in that they can be completely described by their mean and variance. These distributions are particularly useful because of the central limit theorem, which posits that when a large number of independent random variables are added, the distribution of their sum is approximated by a normal distribution. In other words, normal distributions can be applied to most problems Recall the probability density function of the Univariate Gaussian with mean and variance...

  • Please answer both 1 & 2. 1. Use Excel to generate 100 observations from the standard...

    Please answer both 1 & 2. 1. Use Excel to generate 100 observations from the standard Normal distribution. a.Make a histogram of these observations. How does the shape of this histogram compare with a Normal density curve? 2. Use Excel to generate 100 Normally distributed random values (that is 100 outcomes of a Normally distributed random variable with mean 10 and standard deviation of 5). a. Make a histogram for your data. How does the shape of this histogram compare...

  • Please use html format! II. The goal of this problem is to simulate the distribution of the sample mean. We will...

    Please use html format! II. The goal of this problem is to simulate the distribution of the sample mean. We will use the buit load the dataset and avoid some problems, copy and paste the following command in dataset 1ynx. To lynx as.numeric(lynx) Assume this vector represents the population. Le, the mean of this vector is our "true mean" (a) Draw a histogram of the population, find the "true" mean, and the true" variance. Does this data look normally distributed?...

  • R problem 1: The reason that the t distribution is important is that the sampling distribution...

    R problem 1: The reason that the t distribution is important is that the sampling distribution of the standardized sample mean is different depending on whether we use the true population standard deviation or one estimated from sample data. This problem addresses this issue. 1. Generate 10,000 samples of size n- 4 from a normal distribution with mean 100 and standard deviation σ = 12, Find the 10,000 sample means and find the 10,000 sample standard deviations. What are the...

  • Software can generate samples from (almost) exactly Normal distributions. Here is a random sample of size...

    Software can generate samples from (almost) exactly Normal distributions. Here is a random sample of size 5 from the Normal distribution with mean 8 and standard deviation 2: 4.47 5.51 8.1 11.63 7.91 Although we know the true value of μ suppose we pretend that we do not and we test the hypotheses Ho : μ-5.6 a:μ 5.6 at the α 0.05 significance level. What is the power of the test against the alternative μ 8 (the actual population mean)?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT