Question

Suppose we want to simulate the following linear model: Bo + BiX; + Ei where ti~ N(0,22). Assume Xi~ N(0,12), Bo = 0.5 and 31

I need to plot a histogram for estimates of Beta_0 and Beta_1 (over the 100 simulations). I know I can use the coefficients function with the model to display these estimates for each simulation, but how can I access them individually, or save them to a column vector such that I can plot the histogram as needed?

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

R code:

n.sim=100
b0=1:n.sim*0
b1=1:n.sim*0
for(i in 1:n.sim)
{
e=rnorm(10,0,2)
x=rnorm(10,0,1)
y=0.5+2*x+e
model=lm(y~x)
b0[i]=model$coefficients[1]
b1[i]=model$coefficients[2]
}
par(mfrow=c(1,2))
hist(b0,xlab=expression(beta[0]),main=expression(beta[0]),freq=FALSE)
hist(b1,xlab=expression(beta[1]),main=expression(beta[1]),freq=FALSE)

Density 0.0 0.1 0.2 0.3 0.4 0.5 0.6 - -1.5 -0.5 BO Во 0.5 - 1.5 Density 0.0 0.1 0.2 0.3 0.4 0.5 - 0 1 B1 N 1 B1 3 1 +

Add a comment
Know the answer?
Add Answer to:
I need to plot a histogram for estimates of Beta_0 and Beta_1 (over the 100 simulations)....
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
  • Please include all code from R that was used to calculate everything. Problem 2 (0.5 x...

    Please include all code from R that was used to calculate everything. Problem 2 (0.5 x 3 = 1.5 point ) Simulate a sample of y1, ..., 4100 from a simple linear model Y = 1 + 2x + €, where € ~ N(0,62), and x is an arithmetic sequence from 1 to 100, with a step size of 1. Run set.seed(1) to set the seed of R's random number generator so that the simulation can be reproduced. • Make...

  • Please solve the question Simulation: Assume the simple linear regression model i = 1,... , n Ул 3D Во + B1; + ei, N(0,...

    Please solve the question Simulation: Assume the simple linear regression model i = 1,... , n Ул 3D Во + B1; + ei, N(0, o2) for i = 1,...,n. where e Let's set Bo = 10, B1 = -2.5, and n = 30 (a) Set a = 100, and x; = i for i = 1,...,n. (b) Your simulation will have 10,000 iterations. Before you start your iterations, set a random seed using your birthday date (MMDD) and report the...

  • How do I set the problems below in R? Use the rnorm function in R to...

    How do I set the problems below in R? Use the rnorm function in R to generate 100 samples of X ~N(-1.0,2.5) (for help use ?rnorm ) and for each draw, simulate Yǐ from the simple linear regression model = 2.5+2.0x,+티, where e, N N(0,3 ). (ii) Split the sample into 2 subsets of size 25 and 75. For each subset, run the regression of Y on X. Add each fitted regression line (use color) to your plot from (i)....

  • How do I set the problems below in R? Use the rnorm function in R to...

    How do I set the problems below in R? Use the rnorm function in R to generate 100 samples of X ~N(-1.0,2.5) (for help use ?rnorm ) and for each draw, simulate Yǐ from the simple linear regression model = 2.5+2.0x,+티, where e, N N(0,3 ). We were unable to transcribe this image

  • How do I set the problems below in R? Use the rnorm function in R to...

    How do I set the problems below in R? Use the rnorm function in R to generate 100 samples of X ~N(-1.0,2.5) (for help use ?rnorm ) and for each draw, simulate Yǐ from the simple linear regression model = 2.5+2.0x,+티, where e, N N(0,3 ). (iii) What is the marginal sample mean for Y? What is the true marginal mean?

  • Simulations are a very powerful tool data scientists use to test and verify statistical behaviors. Let’s...

    Simulations are a very powerful tool data scientists use to test and verify statistical behaviors. Let’s pretend we know that the true underlying population regression line is as follows (this is almost never the case in real life) : Yi = 2 + 3xi + i (i = 1, . . . , n), i ∼ N (0, 2 2 ). This tells us that the parameters β0 = 2, β1 = 3, and σ = 2. a. Generate 100...

  • Problem 7. Consider the simple linear regression model Y1 = Bo + BiX; +€; for i=1,2,...,n...

    Problem 7. Consider the simple linear regression model Y1 = Bo + BiX; +€; for i=1,2,...,n where the errors Eį are uncorrelated, have mean zero and common variance Varſei] = 02. Suppose that the Xį are in centimeters and we want to write the model in inches. If one centimeter = c inch with c known, we can write the above model as Yį = y +71 Zitki where Zi is Xi converted to inches. Can you obtain the least-squared...

  • #5 is only I need in which we need to plot it on Matlab and I...

    #5 is only I need in which we need to plot it on Matlab and I don't know how to plot it. Project 1 A Vibration Insulation Problem Passive isolation systems are sometimes used to insulate delicate equipment from unwanted vibrations. For example, in order to insulate electrical monitoring equipment from vibrations present in the floor of an industrial plant, the equipment may be placed on a platform supported by flexible mountings resting on the floor. A simple physical model...

  • Solve d,e and f please using R code Part I: qqplots This part deals with qqplots...

    Solve d,e and f please using R code Part I: qqplots This part deals with qqplots of all kinds. Let's do some easy expe riments, first. Let's take a sample from a normal distribution with mu-2, sigma 3, and then look at the hist and the qqplot of that data: set.seed(3) n 100 # Sample size x norm(n,2,3) # Sample from N(mu-2, sigma-3) hist(x) # Looks normal. But that depends on breaks. qqnorm(x) # This doesn't depend on binsize, and...

  • R STUDIO Create a simulated bivariate data set consisting of n 100 (xi, yi) pairs: Generate...

    R STUDIO Create a simulated bivariate data set consisting of n 100 (xi, yi) pairs: Generate n random a-coordinates c from N(0, 1) Generate n random errors, e, from N(0, o), using o 4. Set yiBoB1x; + , Where Bo = 2, B1 = 3, and eN(0, 4). (That is, y is a linear function of , plus some random noise.) (Now we have simulated data. We'll pretend that we don't know the true y-intercept Bo 2, the true slope...

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