Load required packages

library(tidyverse)
library(ggplot2)
library(lme4)
library(broom)
library(ggthemes)
library(MuMIn)

devtools::load_all(".")

Load graph theme

team_theme <- function() {list(

  theme(axis.line = element_line(color = "black"),
        text = element_text(size = 8, family = "Times"),
        panel.background = element_rect(fill = 'white', colour = 'black'),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        plot.title = element_text(colour =  "black", size = 14, hjust = 0.5),
        legend.text = element_text(size = 12, family = "Times")),
  scale_colour_colorblind())
}

Run linear model

base <- glm(log.oy ~ log.AFR , data=mammals_sub)
summary(base)
tidy(base, conf.int=TRUE)
broom::augment(base) %>%
    ggplot(aes(x=log.AFR, y=.fitted)) +
    geom_line() +
    geom_point(aes(x=log.AFR, y=log.oy)) +
    geom_line(aes(y=.fitted)) +
     labs(x = "ln (Age of First Reproduction)", y = "ln (Offspring per Year)")+
  team_theme()

Run linear mixed effects model

b <- lmer(log.oy ~ log.AFR + (log.AFR | order), data=mammals_sub)
summary(b)
lme4::ranef(b)
tidy(b, conf.int=TRUE)
broom::augment(b) %>%
    ggplot(aes(x=log.AFR, y=.fixed)) +
    geom_line( color = 'Purple') +
    geom_point(aes(x=log.AFR, y=log.oy, color = order), alpha = 0.15) +
    geom_line(aes(y=.fitted, color=order))+
    labs(x = "ln (Age of First Reproduction )", y = "ln (Offspring per Year)")+
  team_theme()+
    theme(legend.title=element_blank())

Compare fits of models

MuMIn::model.sel(b, base, rank=AIC)
 smoke <- matrix(c((-0.6037+-0.07162499),(-0.6037+-0.29501976),(-0.6037+-0.11174519),(-0.6037+ 0.25183326),(-0.6037+0.42672130),(-0.6037+-0.28274597),(-0.6037+0.08258135)),ncol=1,byrow=TRUE)
colnames(smoke) <- c("Slope")
 rownames(smoke) <- c("Artiodactyla", "Carnivora", "Cetacea", "Insectivora", "Lagomopha", "Primates", "Rodentia")
 smoke <- as.table(smoke)
 smoke


UofTCoders/eeb430.2017.Python documentation built on May 28, 2019, 3:19 p.m.