Generalized Additive Models

Fits and interprets generalized additive models in R using the mgcv package.

Updated Mar 7, 2026
One-click install
npx skills add https://github.com/ntluong95/agent-skills-statistics --skill generalized-additive-models
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Generalized Additive Models
Source: https://github.com/ntluong95/agent-skills-statistics/tree/main/skills/statistical-computing/gam
Command: npx skills add https://github.com/ntluong95/agent-skills-statistics --skill generalized-additive-models

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a standardized approach to fitting and diagnosing Generalized Additive Models (GAMs) in R, specifically using the mgcv package, helping users effectively model non-linear relationships in their data.

Core Features & Use Cases

  • Flexible Modeling: Fit models with univariate and multivariate smooth terms using various basis functions.
  • Model Diagnostics: Assess smooth term adequacy, concurvity, and effective degrees of freedom.
  • Use Case: When analyzing the non-linear relationship between air pollution exposure and health outcomes over time, use this Skill to fit a GAM with smooth terms for both exposure and time, and then check for concurvity between these smooths.

Quick Start

Use the Generalized Additive Models skill to fit a GAM model with a quasipoisson family and smooth terms for 'time' and 'temperature' to the 'health_data' dataframe.

Frequently Asked Questions about Generalized Additive Models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fit a GAM in R using mgcv with smooth terms for time and temperature?

To fit a GAM in R using mgcv, specify your model formula with smooth terms like s(time) and s(temperature), and set the family argument to quasipoisson. This models non-linear relationships effectively within your dataframe.

What is concurvity in GAM model diagnostics and how do I check it?

Concurvity in GAM diagnostics measures the degree of collinearity between smooth terms, similar to multicollinearity in linear models. You check concurvity using mgcv's built-in diagnostic tools to identify overlapping smooth term patterns.

Can I use REML or GCV for smoothing parameter selection in mgcv?

Yes, mgcv supports both REML and GCV for smoothing parameter selection in Generalized Additive Models. You specify the method argument in the gam function, with REML generally recommended for more stable penalization performance.

How do I assess basis dimension adequacy for smooth terms in a GAM?

Assess basis dimension adequacy by checking the effective degrees of freedom and diagnostic outputs in mgcv. If the effective degrees of freedom approaches the maximum basis dimension, you should increase the k parameter for that smooth term.

Does mgcv integrate with DLNM for penalized distributed lag models?

Yes, mgcv integrates with DLNM to fit penalized distributed lag models. This allows you to model exposure-lag-response relationships while applying automatic penalization to the smooth lag terms.

When should I use Generalized Additive Models instead of standard linear models?

Use Generalized Additive Models when your data exhibits non-linear relationships that standard linear models cannot capture. GAMs fit flexible smooth functions to predictors, allowing you to model complex curves without manually specifying polynomial degrees.