Last active
August 8, 2022 09:12
-
-
Save padpadpadpad/e516b568580d3b9fd188edecef409e8b to your computer and use it in GitHub Desktop.
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
# example of map2 | |
# load packages | |
library(nls.multstart) | |
library(rTPC) | |
library(tidyverse) | |
# load data and keep only 2 curves | |
data("chlorella_tpc") | |
d <- chlorella_tpc %>% | |
filter(curve_id <=2) | |
# nest data frame | |
d <- group_by(d, curve_id, process, flux, growth_temp) %>% | |
nest() | |
# calculate start values for each curve and add them as a list element | |
d <- mutate(d, start_vals = map(data, ~get_start_vals(.x$temp, .x$rate, model_name = 'gaussian_1987'))) | |
# look at d | |
d | |
d$start_vals[[1]] | |
# fit nls.multstart to each unique dataset with each unique set of start values using map2 | |
d <- mutate(d, fit = map2(data, start_vals, ~nls_multstart(rate~gaussian_1987(temp = temp, rmax,topt,a), | |
data = .x, | |
iter = c(3,3,3), | |
start_lower = .y - 10, | |
start_upper = .y + 10, | |
supp_errors = 'Y', | |
convergence_count = FALSE))) | |
d$fit[[1]] | |
d$fit[[2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment