Answer to Question #37591 in Programming & Computer Science for Jason

Question #37591
I need to write a program that does the following in R:

I have a data set (42 rows, 2 columns) of y variables and x variables.

I want to randomly select 12 rows from this matrix and record the coefficients (slope and intercept) of a linear regression of the randomly generated matrix. I would also like to write a loop for this so I can repeat this 1000 times, so I can then have a matrix with 1000 rows and 2 columns filled in with the slopes and intercepts of the 1000 randomly selected sets of 12 rows from my data set.

I am able to get this far but do not know how to incorporate a loop into the code, and a way to store the coefficients into a a matrix.

# Box.Z and Box.DC.gm are columns of data used to generate my initial matrix of data

A <- matrix(c(Box.Z, Box.DC.gm), nrow=42)
B <- A[sample(42, 12), ]
C <- lm(B[,2] ~ B[,1])
D <- matrix(c(coefficients(C)), ncol =2)
1
Expert's answer
2014-01-17T09:19:14-0500
Dear customer,
Unfortunately, your question requires a lot of work and cannot be done for free.
Please submit it with all requirements as an assignment to our control panel and
we'll assist you.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS