r - Loop linear regrssion model -


i have data amount dependent variable , len,age, quantity , pos explanotry variables. trying make regression of amount on age, quantity , pos using stepwise.

    id sym month amount len age quantity  pos     11  10   1    500    5   17   0       12     22  10   1    300    6   11   0       11      33  10   1    200    2   10   0       10     44  10   1    100    2   11   0       11     55  10   1    150    4   15   0       12     66  10   1    250    4   16   0       14     11  20   1    500    5   17   0       12     22  20   1    300    6   11   0       11      33  20   1    200    2   10   0       10     44  20   1    100    2   11   0       11     55  20   1    150    4   15   0       12     66  20   1    250    4   16   0       14     77  20   1    700    4   17   0       11     88  20   1    100    2   16   0       12     11  30   1    500    5   17   0       12     22  30   1    300    6   11   0       11      33  30   1    200    2   10   0       10     44  30   1    100    2   11   0       11     55  30   1    150    4   15   0       12     66  30   1    250    4   16   0       14     11  40   1    500    5   17   2000    12     22  40   1    300    6   11   1000    11      33  40   1    200    2   10   1000    10     44  40   1    100    2   11   1000    11     55  40   1    150    4   15   1000    12     66  40   1    250    4   16   1000    14 

and output of results want after running regression should dataframe that's (that should me detect outliers):

id month sym amount len age quantity pos r^2 cookdistanse  residuals upperlimit lowerlimit 11   1    10  500    5   17   null    12  0.7   1.5         -350      -500       1000  22   1    10  300    6   11   null    11  0.8   1.7         -400      -500       1000 

that's code trying run on sym = 10, sym= 20, sym = 30, sym = 40. have 400 sym values run regression analysis on them.

fit[i]  <-  step(lm (sym[i]$sum ~ len + age + quantity,                     na.action=na.omit), direction="backward") r_sq <- summary(fit[i])$r.squared res[i] <- resid(fit[i]) d[i] <- cooks.distance(fit[i])  q[i] <- quantile(resid(fit[i), c(.25, .50,  .75, .99)) l[i]<-  q[1][i] - 2.2* (q[3][i]-q[1][i]) u[i] <- q[3][i] + 2.2*(q[3][i]-q[1][i]) 

"i" means results regression of sym = (10,20..). way on loop every sym value? highly appreciate.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -