extract - Creating a matrix of coefficients from coef function in R -


from code:

    treatment     <- factor(rep(c(1, 2), c(43, 41)),                          levels = c(1, 2),                         labels = c("placebo", "treated")) improved      <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)),                         levels = c(1, 2, 3),                         labels = c("none", "some", "marked"))     numberofdrugs <- rpois(84, 10) + 1     healthvalue   <- rpois(84, 5)    y             <- data.frame(healthvalue, numberofdrugs, treatment, improved) test          <- glm(healthvalue~numberofdrugs+treatment+improved + treatment:improved, y, family=poisson) summary(test) 

we following using coef() function:

> coef(test)                     (intercept)                   numberofdrugs                treatmenttreated                      1.549172817                     0.004261529                     0.014634807                     improvedsome                  improvedmarked   treatmenttreated:improvedsome                      0.201150827                    -0.129251907                    -0.258841251  treatmenttreated:improvedmarked                      0.051326071  

i wish arrange coefficients of variables vectors , coefficients of interactions matrix, able more work them.

for example:

coef.intercept=(1.5491)  coef.numberofdrugs=(0.00426)  coef.treatment=(0, 0.01463)  coef.improved=(0, 0.2011, -0.1292) 

and correlation matrix treatment rows , improved columns, this:

coef.correlation=

(0       0       0  )  (0  -0.2588  -0.2588) 

is there efficient way this?

note of coefficients not listed in coef() function shall set 0 , have shortened of numbers above.

i believe alleffects effects package may of interest:

library(effects) alleffects(test)  model: healthvalue ~ numberofdrugs + treatment + improved + treatment:improved   numberofdrugs effect numberofdrugs        6        8       10       12       14       16       18       20  4.050962 4.322559 4.612365 4.921601 5.251570 5.603662 5.979360 6.380247    treatment*improved effect          improved treatment     none       marked   placebo 4.416773 3.713517 5.461153   treated 4.596433 4.902746 5.309627 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -