Linear Regression and group by in R -
I want to make a linear regression in R by using the lm ()
function. My data is an annual series for the year (22 years) and an annual series for other states (50 states). I want to fit in regression towards each state so that I finally have a Vector of LM reactions. I can visualize the loop for each state, then I am retrograting inside the loop and connecting the results of each regression in the vector. It does not quite like R, however, I do a 'statement' in SAS and will be done by a 'group' in SQL. What is the way to do this?
This is a method of lme4
package.
& gt; Library (lme4) & gt; D & LT; - data.fr (state = representative (c ('ny', 'ca'), c (10, 10)), + year = delegate (1:10, 2), + reaction = c (rnorm (10) Ranormum (10))) & gt; Explode (reaction ~ year, group = state, data = D, type = 'l') & gt; Fits & lt; - lmList (reaction ~ year | state, data = d) & gt; Call fits: LMList (formula = response ~ year | state, data = D) Coefficient: (interception) year CA-1, 1,442,090 0.17139 9 63 EN 0.00196176 -0.01852429 Freedom degree: 20 total; 16 residual residual standard error: 0.8201316
Comments
Post a Comment