## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") if (!"package:drmTMB" %in% search()) { library(drmTMB) } ## ----first-model-data--------------------------------------------------------- set.seed(13) n <- 120 dat <- data.frame( habitat = factor(rep(c("forest", "grassland"), each = n / 2)), temperature = rnorm(n) ) mu <- 1 + 0.6 * (dat$habitat == "grassland") + 0.4 * dat$temperature sigma <- exp(-0.5 + 0.45 * (dat$habitat == "grassland")) dat$growth <- rnorm(n, mean = mu, sd = sigma) ## ----first-model-fit---------------------------------------------------------- fit <- drmTMB( drm_formula(growth ~ habitat + temperature, sigma ~ habitat), family = gaussian(), data = dat ) check_drm(fit) ## ----first-model-interpret---------------------------------------------------- sigma_habitat <- coef(fit, "sigma")["habitatgrassland"] data.frame( residual_sd_ratio = exp(sigma_habitat), residual_variance_ratio = exp(2 * sigma_habitat) )