I'm sure this is an easy thing to do, but I can't seem to get it right. My 
first question is:  Is there a way to set the intercept of a glm to be an 
overall average of the response variable, as opposed to the coefficient 
for a particular term. 

For example, let's say there are 2 variables (1 and 2) with levels A, B, C 
and D, E, F, respectively.  The default glm output provides an intercept 
term that is the coefficient for A*D and seperate terms for B, C, F, B*F, 
and C*F.  My issue is that I don't always have estimates for certain 
interactions.  When I try to predict values for new data using the 
coefficients from the model, predict.glm assumes the NAs are 0 and, 
therefore, those coefficients have the same estimate as the intercept plus 
other main effects for which there are data.  So, if there's an easy way 
to do that, that would be great.  If not...

...I could do it by changing the design matrix.  I've played with glm.fit 
and model.matrix to create the design matrices, but I'm having trouble 
using them in glm.  I created a matrix and populated it, but when I use 
the saved glm.fit as the "method" argument in glm, I get:
'Error in switch(method, model.frame = return(mf), glm.fit = 1, 
stop("invalid 'method': ",  :switch: EXPR must return a length 1 vector"

EX
glm.fit(x=model.matrix(Y ~ X+Z), y=c(1,...,1))
glm(Y ~ X+Z, family='binomial', method=glm.fit)

So, I guess my question is: How do I include the design matrix so that the 
glm function uses it instead of the default design matrix?

Thanks,
Adam Green
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to