12 June 2021 18:49 Chapter 8 (no week 7) CATEGORICAL GLM LINEAR PREDICTORS - "general linear models" Types of tests can be organised into a framework of analyses called GENERAL LINEAR MODELS (although sometimes referred to simply as "linear models" too). Key to the general linear model is the type of data you're analysing (this is why it is so important to be able to identify different types of data), and the combinations of different variables. Here is a tree of models that combines different types of explanatory variables. It indicates how the different types of GLM map on to traditional stats tests: numeric explanatory variable Equivalent "traditional" stats test regression one -explanatory variable -two categories -> T-test categorical -explanatory variable more than two categories GLM with ... Analysis of variance (ANOVA) 1,1 Multiple regression numeric ... two explanatory- variables + numeric + categorical + numeric + categorical Analysis of covariance (ANCOVA) categorical ... 2-way ANOVA 20 Countries + H 10 + + +++ 0 4 6 Continents The GLM equation: y = Bo + B1x + E The two components of a GLM: · the LINEAR PREDICTOR, which is effectively a line or lines of best fit. · the RESIDUAL ERROR, which is made up of the residuals, which are the "left over" vertical distances between the linear predictor and the data points. The linear predictor is the bold line, and the residuals are the vertical dotted lines. · The linear predictor part is Bo + B1x · The error part is € ('epsilon', the Greek letter e) Fitting a GLM The function for fitting a simple GLM is Im(). This stands for "linear model", which is also a shorthand for these models. The two most important arguments of the Im() function are: · The model formula in the form y ~ x o said like "y as a function of x" o the ~ is a 'tilde', pronounced 'til-da'. · The data GLM PARAMETERS "Parameters" is the names for the slopes and intercepts of the model. When you have a continuous response variable and a continuous explanatory
Plotting a line of best fit variable, as for this chapter, there are two parameters: · BOBO the intercept · B1ß1 the slope To see the parameters of your model, all you have to do is use summary(). We use stat_smooth() to add different types of "smoothed" lines. As we're using Im() to fit our plots, we tell the function to use method = "Im" to create the line: scatter <- ggplot(reac_eyes_data, aes(x = eyesight, y = reaction)) + geom_point() + theme_minimal() scatter + stat_smooth(method = "Im", se = FALSE) The null model To test whether the explanatory variable is significant or not in a GLM, we always compare it to another "view" of the world; another GLM where the variable of interest is removed. A regression-style GLM like in this Chapter is compared to the null model. The null model: · contains no explanatory variable . the linear predictor is