library(lme4) d <- read.csv("my.file.csv") #... #... o1 <- lmer(d$d1 ~ d$d2 + (1|d$d3)) #... #... plot(d$d2, d$d1)
library(lme4) flu.data <- read.csv("my.file.csv") #... #... res <- lmer(antigenic.distance ~ num.mutation + (1 | date), data = flu.data) #... #... plot(antigenic.distance ~ num.mutation, data = flu.data)
library(lme4) flu.data <- read.csv("my.file.csv") # Some light processing to get data into correct format #... #... # Now the analyses – a linear mixed effect model res <- lmer(antigenic.distance ~ num.mutation + (1 | date), data = flu.data) # Checking the model is a good one #... #... # Phew, it is, so plot the best explanatory and response variables! plot(antigenic.distance ~ num.mutation, data = flu.data)
library(lme4) # Function to load in data from file and process read_flu_data <- function(filename) { #' Load in data from file and process data <- read.csv(filename) # Some light processing to get into correct format #... data } flu.data <- read_flu_data("my.file.csv") # Now the analyses – a linear mixed effect model res <- lmer(antigenic.distance ~ num.mutation + (1 | date), data = flu.data) # Checking the model is a good one #... #... # Phew, it is, so plot the best explanatory and response variables! plot(antigenic.distance ~ num.mutation, data = flu.data)
helper.R
# All of the helper functions for our # experiments library(lme4) read_flu_data <- function(filename) { # Load data and process it data <- read.csv(filename) # Wrangle data #... data } check_flu_model <- function(model.out) { # Check model is.good.model <- #... #... is.good.model }
script.R
# Load in our generic helper functions source("helper.R") # Load data and process it my.data <- read_flu_data("my.file.csv") # Analyses - linear mixed effect model res <- lmer(antigenic.distance ~ num.mutation + (1 | date), data = flu.data) # Check model if (!check_flu_model(res)) stop("Model is rubbish, give up now!") # Plot the best explanatory and # response variables plot(antigenic.distance ~ num.mutation, data = flu.data)