r - prevent the name of model.matrix to appear in the results on a regression -


is possible use model matrix in regression without having name of model matrix in regression results?

i need go through such procedure have interactions have no observation. (i.e) results of interaction na.

a related question can found here.

here data illustrate point:

mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv") str(mydata)  gre_ <- mydata$gre-mean(mydata$gre)  <- model.matrix(~-1+gre_:factor(rank),data=mydata)[,-c(2)]  summary(glm(admit~gpa+gre+factor(rank)+a,data=mydata, family=binomial)) 

results

call: glm(formula = admit ~ gpa + gre + rank + a, family = binomial,  data = mydata)  deviance residuals:      min       1q   median       3q      max   -1.6449  -0.8886  -0.6332   1.1706   2.1949    coefficients:                       estimate std. error z value pr(>|z|)     (intercept)         -3.0039781  1.4012928  -2.144   0.0321 *   gpa                  0.7634679  0.3297215   2.315   0.0206 *   gre                  0.0016098  0.0016634   0.968   0.3332     rank                -0.5584921  0.1288588  -4.334 1.46e-05 *** agre_:factor(rank)1  0.0014010  0.0028001   0.500   0.6168     agre_:factor(rank)3  0.0010074  0.0025007   0.403   0.6871     agre_:factor(rank)4  0.0009936  0.0034111   0.291   0.7708     --- 

how rid of model.matrix name a in results?

if run formula syntax, r going put "a" there. can extract names of coefficients , remove first "a" if gsub() or use substr() remove first letter. depends on how want process them down line.

the other option use glm.fit , specify complete model matrix yourself. like

a <- model.matrix(~-1+gre_:factor(rank),data=mydata)[,-c(2)] b <- model.matrix(~gpa+gre+rank, data=mydata) mm<-cbind(b,a)  ff<-glm.fit(mm,mydata$admit, family=binomial()) class(ff)<-c("glm","lm") summary(ff) 

will return

call: null  deviance residuals:      min       1q   median       3q      max   -1.6449  -0.8886  -0.6332   1.1706   2.1949    coefficients:                      estimate std. error z value pr(>|z|)     (intercept)        -3.0039781  1.4012928  -2.144   0.0321 *   gpa                 0.7634679  0.3297215   2.315   0.0206 *   gre                 0.0016098  0.0016634   0.968   0.3332     rank               -0.5584921  0.1288588  -4.334 1.46e-05 *** gre_:factor(rank)1  0.0014010  0.0028001   0.500   0.6168     gre_:factor(rank)3  0.0010074  0.0025007   0.403   0.6871     gre_:factor(rank)4  0.0009936  0.0034111   0.291   0.7708     --- signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  (dispersion parameter binomial family taken 1)      null deviance: 499.98  on 399  degrees of freedom residual deviance: 459.13  on 393  degrees of freedom aic: 473.13  number of fisher scoring iterations: 4 

here estimates same , variable names untouched. since not technically real glm object fibbing bit adding class information, have same properties (you can see "call" missing) , in cases should behave regular glm object functions, including summary().


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -