Extract Regression P Value in R -


i performing multiple regressions on different columns in query file. i've been tasked extracting results regression function lm in r.

so far have,

> reg <- lm(query$y1 ~ query$x1 + query$x2) > summary(reg)  call: lm(formula = query$y1 ~ query$x1 + query$x2)  residuals:     1     2     3     4    7.68 -4.48 -7.04  3.84   coefficients:             estimate std. error t value pr(>|t|) (intercept)  1287.26     685.75   1.877    0.312 query$x1      -29.30      20.92  -1.400    0.395 query$x2     -116.90      45.79  -2.553    0.238  residual standard error: 11.97 on 1 degrees of freedom multiple r-squared:  0.9233,    adjusted r-squared:  0.7699  f-statistic: 6.019 on 2 , 1 df,  p-value: 0.277 

to extract coefficients, r-squared , f statistics use following:

reg$coefficients summary(reg)$r.squared summary(reg)$fstatistic 

i extract p-value of 0.277.

is there piece of code this?

thanks

i recommend using "broom" package practice go forward cases (where might need create data frame model fit output).

check simple example:

library(broom)  dt = data.frame(mtcars) # example dataset  model = lm(mpg ~ disp + wt, data = dt) # fit model  summary(model) # usual summary of model fit  tidy(model) # coefficient table data frame  glance(model) # rest of stats data frame  glance(model)$p.value # p value 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -