
Explore linear regression and its extensions with generalized linear models and generalized additive models, relaxing linearity assumptions to model binary and count data with nonlinear polynomials and smooths.
Install the R software, RStudio, and the R Commander, download the materials zip from view resources, and complete the exercises while using the discussion board for questions.
Explore linear models, generalized linear models, and generalized additive models in R, with a focus on data types—count, proportion, and binary—and how to choose appropriate distributions.
The term "linear" refers to the fact that we are fitting a line. The term model refers to the equation that summarizes the line that we fit. The term "linear model" is often taken as synonymous with linear regression model.
Assumptions of Linear Models (regression):
Explain that beta-hat is a random normal estimator with mean equal to the true beta, discuss its sampling variance, and reveal an unbiased sigma-squared estimator from residuals for confidence intervals.
Estimate the age of the universe by fitting a linear model to galaxy velocities and distances using Doppler measurements and Hubble's constant, testing the Big Bang theory.
Explore live R setup using the R commander to load packages and run Hubble data analyses. Use the lm function to perform linear regression on velocity and distance.
Learn to fit a simple linear regression in R, including suppressing the intercept and estimating the beta coefficient, then use summary and residual plots to assess model fit.
Refit a linear model on the Hubble data in R, compare models with AIC and BIC, and estimate the universe’s age from Hubble’s constant.
Explore linear modeling and generalized linear and additive models in R, compare models with anova and aic, and interpret confidence intervals, t-statistics, and residual diagnostics.
practice building linear models with the warp brakes data, exploring an interaction, estimating three models where stopping distance depends on speed (with speed squared and intercept), and comparing them.
In statistics, the generalized linear model (GLM) is a flexible generalization of ordinary linear regression that allows for response variables that have error distribution models other than a normal distribution. The GLM generalizes linear regression by allowing the linear model to be related to the response variable via a link function and by allowing the magnitude of the variance of each measurement to be a function of its predicted value.
Explore generalized linear models, distinguishing the linear predictor from the transformed predictive value via link functions, including canonical links, and interpret coefficients through the inverse of the link function.
Explore generalized linear models for counts and proportions, using binomial errors and the logit link, and learn to evaluate model fit with deviance and degrees of freedom.
Explain probability vs. odds and the logit link in binomial GLMs. Demonstrate predicting heart attack probability from CK levels and loading data in R with read.csv.
Proportion data has values that fall between zero and one. Naturally, it would be nice to have the predicted values also fall between zero and one. One way to accomplish this is to use a generalized linear model (glm) with a logit link and the binomial family.
Model binomial heart attack data with a logit GLM, from proportion to two-column counts, and interpret the sigmoid relationship with CK levels.
Construct and interpret a baseline binomial model, inspect deviance and residuals, assess normality and dispersion, and use diagnostic plots to justify adding a cubic term.
Plot fitted values against actual outcomes to assess fit as we add squared and cubic terms. Use anova and chi-square tests to compare models, preferring the more complex when needed.
Explore logistic regression on binary data, interpret results, and extend with Poisson and quadratic GLMs and GAMs in R, comparing model fit.
Explore the agenda from proportions and frequencies to binary 0/1 responses, and cover error families and link functions in generalized additive models as a specialized extension of generalized linear models.
Examine linear modeling in R, including factor predictors and GLMs with interaction plots, residual diagnostics, and compare linear and quadratic models for car stopping distance with and without intercept.
Explore linear and quadratic models predicting stopping distance from speed, managing intercept and multicollinearity, compare models with anova and aic, and diagnose residuals with qq plots and cook's distance.
Explore glm exercise solutions with binomial family and logit link, modeling inhibition counts as a proportion of successes against log concentration. Assess linear and quadratic time models via anova-style tests.
In statistics, Poisson regression is a form of regression analysis used to model count data and contingency tables. Poisson regression assumes the response variable Y has a Poisson distribution, and assumes the logarithm of its expected value can be modeled by a linear combination of unknown parameters. A Poisson regression model is sometimes known as a log-linear model, especially when used to model contingency tables.
Poisson regression models are generalized linear models with the logarithm as the (canonical) link function, and the Poisson distribution function as the assumed probability distribution of the response.
Assess Poisson count models by residual deviance, plots, and Cook's distance for fit and outliers. Improve with a quadratic term and compare AIC; consider a negative binomial alternative for overdispersion.
Use a binary response variable when outcomes are 0 or 1, modeled with Bernoulli/binomial GLM and logit or log-log link, illustrated by bird presence on islands with area and isolation.
Explore logistic regression with binomial errors to predict a binary bird presence from island area and isolation, compare models with and without interaction using anova, and interpret logit-based odds.
Fit generalized additive models with smooth terms for area and isolation. Compare models with both terms to isolation only and analyze deviance to assess variable effects.
Log-linear analysis is a technique used in statistics to examine the relationship between more than two categorical variables.
Define deviance as two times the difference in the log likelihood between your model and a saturated model, and address overdispersion in Poisson and binomial GLMs and GAMs.
In statistics, a generalized additive model (GAM) is a generalized linear model in which the linear predictor depends linearly on unknown smooth functions of some predictor variables, and interest focuses on inference about these smooth functions. GAMs were originally developed by Trevor Hastie and Robert Tibshirani to blend properties of generalized linear models with additive models.
Explore how generalized additive models reveal smoothing terms and interactions, including isotropic and tensor product smooths, and visualize three dimensional partial effects on the linear predictor.
Explore generalized additive models for ozone data by fitting smooth, non-linear terms for radiation, temperature, and wind, and compare models with and without radiation using DCV and significance.
Compare generalized additive models for ozone data, test interactions between wind and temperature, and assess model fit with deviance, cross-validation, and smoothing splines to balance bias and variance.
Explore general approaches for fitting GAMs using penalized likelihood methods to control curvature and prevent overfitting, balancing multiple predictor shapes in the linear predictor.
Learn the structure of generalized additive models and how to build GAMs from scratch, representing smooth terms with regression splines and selecting smoothing via generalized cross-validation.
Select a polynomial basis to build a univariate additive model and express f(x) as a fourth-order polynomial with estimated coefficients, scaling x to 0-1.
Model y as an additive sum of univariate polynomial basis functions in GAMs. See how coefficients shape quadratic and higher-order terms, revealing how polynomial curves exhibit inflection points.
Represent a univariate relation as a linear model using a fourth-order polynomial basis for GAMs, estimate coefficients by least squares on an X matrix, and form f(x) from these terms.
Explore GAMs using a fourth‑order polynomial basis, controlled by lambda for smoothing, with cross-validation to select the basis order and minimize residuals in regressing y on an X matrix.
Examine regression splines built from cubic spline segments joined at knots to form a continuous curve, constraining the additive model and aiding estimation of the response.
Identify knot locations for cubic splines using evenly spaced x-values or observed y-values, and construct the spline basis within a least-squares linear model to estimate y.
Demonstrate cubic splines from scratch by building the basis matrix with knots, estimating coefficients via a linear model, and applying a univariate additive GAM to engine data scaled to 0–1.
Create an R function to establish the cubic spline basis, using r.k for the spline and knots, and an array of x values to produce the model matrix for regression.
Build a GAM by constructing a basis function, generating a model matrix with knots, and fitting a linear model to predict y from scaled x; explore prediction, coefficients, and plotting.
Learn to build a GAM using regression splines, apply a lambda-based smoothing penalty on the second derivative, and compare knot spacing and model complexity for better predictions.
Builds a penalized regression spline with a second-derivative penalty matrix, forms an augmented model matrix with lambda, fits the model, and compares three lambda values to find the optimal fit.
Demonstrate building a univariate GAM in R by scaling x to 0–1, constructing a spline model matrix with knots, and using lambda to control smoothing.
Explore generalized cross-validation to select the smoothing parameter lambda for GAMs, using leave-one-out cross-validation and GCV to minimize prediction error and fit the optimal model.
This lecture extends the univariate additive model to a two-term additive model with two predictors. It addresses identifiability and uses penalized regression splines with cross-validation.
Investigate bivariate GAMs with two explanatory variables by using optimal smoothing values to plot partial effects of girth and height, and explore converting additive models to GAMs with penalized likelihood.
Practice generalized additive modeling by simulating data, fitting fifth- and tenth-order polynomials, and comparing cubic regression spline fits with predict to see how polynomial order and basis affect the lines.
Explore generalized linear models and generalized additive models using real-world examples, from brain imaging to air pollution, and compare models with isotropic and tensor product smooths.
model the cherry tree volume with a generalized additive model (gam) using log(volume) as the response and smooth height and girth, with gamma distribution, generalized cross-validation, and partial residual plots.
The lecture compares smoothing options for gams, from thin plate regression splines to penalized cubic regression splines, and shows how basis dimension and gamma affect degrees of freedom and gcv.
Explore smooth terms with multiple predictors in generalized additive models, modeling height and girth with isotropic and tensor product smooths for scale-insensitive, stable estimates.
Compare thin plate and cubic regression splines, then show tensor product smoothing improves stability and scale handling for multi covariate GAMs.
Mix parametric and smooth terms in generalized additive models, using height as a three-level factor and girth as a smooth predictor to estimate volume; learn anova, summary, and aic insights.
Predict brain activity levels from x and y voxel locations using smooth models in a generalized additive model framework, with region effects and checks for model selection and fit.
Examine how to tune smoothing in generalized additive models for brain imaging data using scale settings, gamma penalties, and generalized cross-validation, and assess fit with residual plots.
this lecture compares a fourth-root transformed brain activity model to a gamma GLM with a log link, showing variance stabilization and improved mean predictions.
Learn how generalized additive models predict brain activity using isotropic smooth terms, additive terms, comparing isotropic interaction (M2) with an additive model (M3). Assess model fit via deviance and prediction.
Assess brain imaging models by comparing additive, isotropic interaction, and tensor product fits using analysis of deviance and DCV; reject additive in favor of isotropic or tensor product.
Explore a semi-parametric generalized additive model for Chicago air pollution and death rates. Smooth time and covariates, use log response for Poisson data, and diagnose with cam check residual plots.
We examine residuals and outliers in mortality data, create four-day lagged aggregates of ozone, temperature, and particulates, and compare a three-way smooth to a tensor-product smooth.
Examine Parshall's interaction term and variable scatter to show time-related patterns in predicted death rate; validate ozone and temperature effects and discuss applying the model elsewhere via the model matrix.
Compare how increasing the basis order affects the fitted line and prediction uncertainty, using fifth and tenth order polynomials and cubic regression splines in R.
Linear Regression, GLMs and GAMs with R demonstrates how to use R to extend the basic assumptions and constraints of linear regression to specify, model, and interpret the results of generalized linear (GLMs) and generalized additive (GAMs) models. The course demonstrates the estimation of GLMs and GAMs by working through a series of practical examples from the book Generalized Additive Models: An Introduction with R by Simon N. Wood (Chapman & Hall/CRC Texts in Statistical Science, 2006). Linear statistical models have a univariate response modeled as a linear function of predictor variables and a zero mean random error term. The assumption of linearity is a critical (and limiting) characteristic. Generalized linear models (GLMs) relax this assumption of linearity. They permit the expected value of the response variable to be a smoothed (e.g. non-linear) monotonic function of the linear predictors. GLMs also relax the assumption that the response variable is normally distributed by allowing for many distributions (e.g. normal, poisson, binomial, log-linear, etc.). Generalized additive models (GAMs) are extensions of GLMs. GAMs allow for the estimation of regression coefficients that take the form of non-parametric smoothers. Nonparametric smoothers like lowess (locally weighted scatterplot smoothing) fit a smooth curve to data using localized subsets of the data. This course provides an overview of modeling GLMs and GAMs using R. GLMs, and especially GAMs, have evolved into standard statistical methodologies of considerable flexibility. The course addresses recent approaches to modeling, estimating and interpreting GAMs. The focus of the course is on modeling and interpreting GLMs and especially GAMs with R. Use of the freely available R software illustrates the practicalities of linear, generalized linear, and generalized additive models.