Created
May 16, 2017 15:46
-
-
Save padpadpadpad/c9a0cef32518efd979d47d21c07b0c5f to your computer and use it in GitHub Desktop.
Getting predictions on a every level of a grouped dataset
This file contains hidden or 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 in packages | |
library(nlsLoop) | |
library(dplyr) | |
library(tidyr) | |
# load up Chlorella data | |
data('Chlorella_TRC') | |
head(Chlorella_TRC) | |
p <- expand.grid(curve_id = unique(Chlorella_TRC$curve_id), | |
growth.temp = unique(Chlorella_TRC$growth.temp)) %>% | |
mutate(., ln.c = rnorm(n(), mean = 2, sd = 1), | |
Ea = rnorm(n(), mean = 0.65, sd = 0.5), | |
Eh = rnorm(n(), mean = 2, sd = 1), | |
Th = rnorm(n(), mean = 310, sd = 4)) | |
# create new dataset of temperature values | |
new_d <- group_by(Chlorella_TRC, curve_id, growth.temp) %>% | |
summarise(., min = min(K, na.rm = FALSE), | |
max = max(K, na.rm = FALSE)) %>% | |
data.frame() %>% | |
group_by(., curve_id, growth.temp) %>% | |
do(data.frame(K = seq(.$min, .$max, length.out = 100))) %>% | |
data.frame() %>% | |
merge(., p, by = c('curve_id', 'growth.temp')) %>% | |
mutate(., pred = schoolfield.high(ln.c, Ea, Eh, Th, temp = K, Tc = 15)) %>% | |
select(., -c(ln.c, Ea, Eh, Th)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment