Last active
January 11, 2017 17:13
-
-
Save padpadpadpad/8759c0e0d663e07ac736bb30829cd6f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load package | |
library(nlsLoop) | |
library(nlme) | |
library(ggplot2) | |
library(dplyr) | |
# create dummy data | |
example <- data.frame(expand.grid(K = 280:330, rep = 1:3)) | |
# create dummy params | |
params <- data.frame(rep = 1:3, | |
ln.c = rnorm(3, mean = 1, sd = 0.5), | |
Ea = rnorm(3, mean = 0.6, sd = 0.2), | |
Eh = rnorm(3, mean = 3, sd = 0.5), | |
Th = rnorm(3, mean = 320, sd = 3)) | |
# create rate data | |
example <- merge(example, params, by = 'rep') %>% | |
mutate(log_rate = schoolfield.high(ln.c, Ea, Eh, Th, temp = K, Tc = 10), | |
rep = as.factor(rep)) | |
# quickplot | |
ggplot(example) + | |
geom_line(aes(K, log_rate, col = factor(rep))) | |
# example mixed model code for a single species | |
# the trickiest part here is knowing how many 0s after the each parameter you need in the start = argument | |
# not needed here as we have no fixed effect factors | |
# set up controls | |
control <- nlmeControl(maxIter = 10000, tol = 1e-15) | |
MM <- nlme(log_rate ~ schoolfield.high(ln.c, Ea, Eh, Th, temp = K, Tc = 10), | |
data = example, | |
fixed = list(ln.c + Ea + Eh + Th ~ 1), | |
random = pdDiag(ln.c + Ea + Eh ~ 1), # doesn't seem to fit with Th in. Too little random variance | |
na.action = na.omit, | |
groups = ~ rep, | |
start = c(1, 0.6, 3, 320), | |
control = control) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment