knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Preliminaries

Load data

Install the mammals milk package if needed.

# install_github("brouwern/mammalsmilk")

You can then load the package with library()

library(mammalsmilk)

The example data is milk_primates

data("milk_primates")

Log transformation makes things more linear.

#this could be done with dplyr::mutate() too
milk_primates$mass.fem.log <- log(milk_primates$mass.fem)

Load libraries

library(ggplot2)
library(ggpubr)
library(cowplot)
library(bbmle)
library(broom)

Linear regression as model fitting

Fit 2 models

Null model (Ho): flat line

lm.null <- lm(fat ~ 1,
              data = milk_primates)

Alternative model: fat ~ log(mass.fem)

lm.mass <- lm(fat ~ mass.fem.log,
              data = milk_primates)

Plot both models

What is the intercept of null model?

The mean fat value is 8.6

summary(milk_primates[,"fat"])

plot


Compare models: significance test

Nested Models:

Hypothesis test of nested models in R

#NOTE: order w/in anova() doesn't matter
anova(lm.null, 
      lm.mass)

Examine model: IT-AIC

IT-AIC background

AIC in practice

AIC in R

AIC in base R

The AIC() command in base R.

AIC(lm.null, 
    lm.mass)

AIC table from AICtab

AICtab() from the bbmle package is super handy. Can give AIC and dAIC. Also can do AICc (see below).

bbmle::AICtab(lm.null,
       lm.mass,
       base = T)

AICc

bbmle::ICtab(lm.null,
      lm.mass,
      type = c("AICc"),
      base = T)

What about R^2?

Hypothesis testing

IC-AIC

R^2

How good is the alternative model?




brouwern/mammalsmilk documentation built on May 17, 2019, 10:38 a.m.