Question

In: Math

Use R to generate n = 400 samples (idependent identically distributed random numbers) of X ∼...

Use R to generate n = 400 samples (idependent identically distributed random numbers) of X ∼ N(0, 4). For each Xi , simulate Yi according to Yi = 3 + 2.5Xi + εi , where εi ∼ N(0, 16), i = 1, ..., n. Use R to solve the following questions. (a) Compute the least square estimators of βˆ 0 and βˆ 1. (b) Draw a regression line according to the numbers computed in (a). Plot Y and X with this regression line. Hint: Use rnorm.

Solutions

Expert Solution

R code with comments

#set the random seed
set.seed(123)

#set the sample size
n<-400
#generate X
x<-rnorm(n,mean=0,sd=sqrt(4))
#generate epsilon
e<-rnorm(n,mean=0,sd=sqrt(16))
#simulate Y
y<-3+2.5*x+e

#a) compute the least square estimators
fit<-lm(y~x)
summary(fit)
sprintf('The estimated value of the intercept (βˆ0) is %.4f',fit$coef[1])
sprintf('The estimated value of the slope (βˆ1) is %.4f',fit$coef[2])

#b) plot x,y and the regression line
plot(x,y,main="Y vs X")
abline(fit,col="red")

# get this

get this plot


Related Solutions

Use the Rejection Method to generate n = 1000 values for a random variable X distributed...
Use the Rejection Method to generate n = 1000 values for a random variable X distributed as Exponential (lambda=5). Create a density histogram for your generated values and superimpose the probability density function of the target distribution to the histogram. Use the generated values to estimate the mean, standard deviation, and the probability that X < 2. Compare them with the theoretic values which are 0.2, 0.2, and 0.97725, respectively. Report the rejection rate. Write in R code
What is the code in Rstudio or R? (a) Generate 200 random samples of size n...
What is the code in Rstudio or R? (a) Generate 200 random samples of size n = 10 from a Poisson distribution with mean λ = 12. i. Calculate sample means for each sample. Report the first 10 sample means. ii. Draw a histogram of the sample means (where the y-axis is the density) and fit a density estimate (default density estimator is ok). iii. What is your finding about the sampling distribution of the sample mean, based on your...
Write the R code to generate five independent uniform random numbers and use that to generate...
Write the R code to generate five independent uniform random numbers and use that to generate 5 independent Bernoulli random variables with probability of success p = 0.4. please use RStudio. please do not use lab nor rbern for calculations.
Let X and Y be independently and identically distributed random variables. Then, what is P (X...
Let X and Y be independently and identically distributed random variables. Then, what is P (X < Y ) (a) in case the common distribution of X and Y is continuous? (b) in case P(X=i)=P(Y =i)= 1, i=1,2,···,n.
Generate 1000 random numbers from ??3? starting with standard normal random numbers in R.
Generate 1000 random numbers from ??3? starting with standard normal random numbers in R.
Use Excel to generate 100 N (10,5) distributed random values (that is 100 values of a...
Use Excel to generate 100 N (10,5) distributed random values (that is 100 values of a Normally distributed random variable with mean 10 and standard deviation 5). Plot histogram for your data. See Appendix on how to generate these values.
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
Let Xi's be independent and identically distributed Poisson random variables for 1 ≤ i ≤ n....
Let Xi's be independent and identically distributed Poisson random variables for 1 ≤ i ≤ n. Derive the distribution for the summation of Xi from 1 to n. (Without using MGF)
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
random samples of 400 bottles of hairspray are distributed in the grocery store. Of the bottles,...
random samples of 400 bottles of hairspray are distributed in the grocery store. Of the bottles, 300 have a cash prize inside the cap. Which of the following is a 90% confidence interval for the true proportion of bottles that have the cash prize at the grocery store?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT