# glm does generalised linear models in R # some fake data x1 <- 1:50 x2 <- rep(1:5, 10) y <- rnorm(50, mean = 1/(2 * x1 + 4 * x2), sd = 0.05) df <- data.frame(y = y, x1 = x1, x2 = x2) # formula species the linear predictor - same syntax as lm # family specifies the distribution of the response and the link function # they are some common defaults for usual dists # look at ?family # for more details # i.e. normal linear regression glm(y ~ x1 + x2, data = df, family = gaussian) # normal linear regression with inverse link glm(y ~ x1 + x2, data = df, family = gaussian(link = "inverse")) fit <- glm(y ~ x1 + x2, data = df, family = gaussian(link = "inverse")) anova(fit) # residuals for a glm fit can be of different types # type = c("deviance", "pearson", "working", "response", "partial"), ...) # deviance residuals residuals(fit, type = "deviance")