## ----eval=FALSE---------------------------------------------------------- ## glm(formula, family, data, weights) ## ----eval=FALSE---------------------------------------------------------- ## family = Gamma(link = "log") ## ----eval=TRUE----------------------------------------------------------- n <- 50 set.seed(19730911) x <- runif(n) f <- sample.int(3, size = n, replace = TRUE) f <- factor(f, levels = 1:3, labels = LETTERS[1:3]) eta <- 0.2*x + 0.1*(f == "B") - 0.1*(f == "C") prob <- exp(eta) / (1 + exp(eta)) y <- rbinom(n, size = 1, prob = prob) xNotUsed <- runif(n) fNotUsed <- sample.int(3, size = n, replace = TRUE) fNotUsed <- factor(fNotUsed, levels = 1:3, labels = LETTERS[1:3]) Data <- data.frame(y = y, x = x, f = f, xNotUsed = xNotUsed, fNotUsed = fNotUsed, eta = eta, prob = prob) head(Data) ## ----eval=TRUE----------------------------------------------------------- fit <- glm(y ~ x + f, family = binomial(link = "logit"), data = Data) ## ----eval=TRUE----------------------------------------------------------- print(fit) ## ----eval=TRUE----------------------------------------------------------- summary(fit) ## ----eval=FALSE---------------------------------------------------------- ## plot(fit) ## ----eval=TRUE----------------------------------------------------------- library("mffSM") plotLM(fit) ## ----eval=TRUE----------------------------------------------------------- coef(fit) fit$coef ## ----eval=TRUE----------------------------------------------------------- summary(fit)$coef ## ----eval=TRUE----------------------------------------------------------- vcov(fit) summary(fit)$cov.scaled ## ----eval=TRUE----------------------------------------------------------- anova(fit, test = "Chisq") ## ----eval=TRUE----------------------------------------------------------- anova(fit, test = "Rao") ## ----eval=TRUE----------------------------------------------------------- drop1(fit, test = "Chisq") ## ----eval=TRUE----------------------------------------------------------- drop1(fit, test = "Rao") ## ----eval=TRUE----------------------------------------------------------- add1(fit, .~. + x:f, test = "Chisq") add1(fit, .~. + x:f + xNotUsed + fNotUsed, test = "Chisq") ## ----eval=TRUE----------------------------------------------------------- fit2 <- glm(y ~ x, family = binomial(link = "logit"), data = Data) fit1 <- fit ## ----eval=TRUE----------------------------------------------------------- anova(fit2, fit1, test = "Chisq") ## ----eval=TRUE----------------------------------------------------------- anova(fit2, fit1, test = "Rao") ## ----eval=TRUE----------------------------------------------------------- confint(fit1) ## ----eval=TRUE----------------------------------------------------------- alpha <- 0.05 qq <- qnorm(1 - alpha/2) be <- coef(fit) se <- sqrt(diag(vcov(fit))) Wald <- data.frame(Estimate = be, Std.Error = se, Lower = be - qq * se, Upper = be + qq * se) print(Wald) ## ----eval=TRUE----------------------------------------------------------- (indexf <- grep("f", names(coef(fit)))) (bef <- coef(fit)[indexf]) (Vf <- vcov(fit)[indexf, indexf]) (Zf <- as.numeric(crossprod(bef, solve(Vf, bef)))) (pWaldf <- pchisq(Zf, df = length(bef), lower.tail = FALSE)) ## ----eval=TRUE----------------------------------------------------------- summary(fit)$dispersion ## ----eval=TRUE----------------------------------------------------------- fit$weights ## ----eval=TRUE----------------------------------------------------------- deviance(fit) fit$deviance ## ----eval=TRUE----------------------------------------------------------- fitted(fit) predict(fit, type = "response") ## ----eval=TRUE----------------------------------------------------------- predict(fit, type = "link") ## ----eval=FALSE---------------------------------------------------------- ## predict(fit, type = "terms") ## ----eval=TRUE----------------------------------------------------------- resid(fit, type = "pearson") residuals(fit, type = "pearson") ## ----eval=TRUE----------------------------------------------------------- resid(fit, type = "deviance") residuals(fit, type = "deviance") ## ----eval=TRUE----------------------------------------------------------- rstandard(fit, type = "pearson") ## ----eval=TRUE----------------------------------------------------------- rstandard(fit, type = "deviance") ## ----eval=TRUE----------------------------------------------------------- cooks.distance(fit) ## ----eval=TRUE----------------------------------------------------------- hatvalues(fit)