In summary.glm I'm trying to get a better feel for the z output. The following lines can be found in the function 1 if (p > 0) { 2 p1 <- 1:p 3 Qr <- object$qr 4 coef.p <- object$coefficients[Qr$pivot[p1]] 5 covmat.unscaled <- chol2inv(Qr$qr[p1, p1, drop = FALSE]) 6 dimnames(covmat.unscaled) <- list(names(coef.p), names(coef.p)) 7 covmat <- dispersion * covmat.unscaled 8 var.cf <- diag(covmat) 9 s.err <- sqrt(var.cf) 10 tvalue <- coef.p/s.err 11 dn <- c("Estimate", "Std. Error") In line 10 where the tvalue is calculated I understand where s.err is coming from and why it is used, but coef.p is throwing me for a loop. First off what is: coef.p <- object$coefficients[Qr$pivot[p1]] giving us? This should be the distance the sample is from the null hypothesis so that when we divide by the standard error we get the t value. Then we would check distance to decide to reject or not. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jacob Davis Actuarial Analyst [[alternative HTML version deleted]]
Davis, Jacob B. <JBDavis <at> txfb-ins.com> writes:> > In summary.glm I'm trying to get a better feel for the z output. The > following lines can be found in the function >[snip] digging through the function is good: debugging your way through the function is sometimes even better. examples(glm,local=TRUE) ## run glm examples and get ## results left in local workspace) ls() debug(summary.glm) summary(glm.D93) shows ... p is object rank (~ number of parameters) Qr$pivot gives the order in which the parameters have been rearranged to solve the model, so Qr$pivot[p1] gives the rearranged order of the coefficients. We need this rearranged order because we're going to extract the unscaled covariance matrix by solving the inverse QR matrix, which is in the pivoted (rearranged) order. The null hypothesis for any particular contrast in glm is that the parameter is 0, so the estimates of the coefficients (object$coefficients) *are* the distance from the null hypothesis. Ben Bolker
Thanks for the insight on the debugger. It has taken me a day or so to get use to it, but it is very helpful. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ben Bolker Sent: Tuesday, June 20, 2006 12:56 PM To: r-help at stat.math.ethz.ch Subject: Re: [R] glm beta hypothesis testing Davis, Jacob B. <JBDavis <at> txfb-ins.com> writes:> > In summary.glm I'm trying to get a better feel for the z output. The > following lines can be found in the function >[snip] digging through the function is good: debugging your way through the function is sometimes even better. examples(glm,local=TRUE) ## run glm examples and get ## results left in local workspace) ls() debug(summary.glm) summary(glm.D93) shows ... p is object rank (~ number of parameters) Qr$pivot gives the order in which the parameters have been rearranged to solve the model, so Qr$pivot[p1] gives the rearranged order of the coefficients. We need this rearranged order because we're going to extract the unscaled covariance matrix by solving the inverse QR matrix, which is in the pivoted (rearranged) order. The null hypothesis for any particular contrast in glm is that the parameter is 0, so the estimates of the coefficients (object$coefficients) *are* the distance from the null hypothesis. Ben Bolker ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html