Skip to content

Commit

Permalink
Minor edits to 1to1 plot and naming of model2 aka multiplicative model
Browse files Browse the repository at this point in the history
  • Loading branch information
akleinhesselink committed Feb 24, 2022
1 parent 71e7138 commit ee137b4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
19 changes: 10 additions & 9 deletions code/fit_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ nls.control(maxiter = 1000, tol = 1e-8, minFactor = (1/10)*(1/1024),

fit1pw <- fit2pw <- list()
fit2HOI <- fit1HOI <- list()
fit3 <- fit2 <- fit1 <- list()
# fit3 <-
fit2 <- fit1 <- list()

for( i in 1:3 ) {
# loop through focal species (i)
Expand Down Expand Up @@ -76,14 +77,14 @@ for( i in 1:3) {
algorithm = 'port'
)

fit3[[i]] <- nls(
log(1/y) ~ log(model3(B1, B2, B3, parms = list(lambda = lambda, alpha = alpha, tau = tau))),
data = temp_data,
start = inits2,
lower = lowers2,
upper = uppers2,
algorithm = 'port'
)
# fit3[[i]] <- nls(
# log(1/y) ~ log(model3(B1, B2, B3, parms = list(lambda = lambda, alpha = alpha, tau = tau))),
# data = temp_data,
# start = inits2,
# lower = lowers2,
# upper = uppers2,
# algorithm = 'port'
# )
}

predicted <- pgrid
Expand Down
29 changes: 15 additions & 14 deletions code/phenomenological_models.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
model1 <- function(B1, B2, B3, parms ){
# Hassel Model
# Hassell Model
with(parms, {
t1 <- (B1*alpha[1])
t2 <- (B2*alpha[2])
Expand All @@ -10,7 +10,8 @@ model1 <- function(B1, B2, B3, parms ){
}

model2 <- function(B1, B2, B3, parms ){
# Model 2, like model 1 but separate
# Model 2, aka "multiplicative model"
# like model 1 but separate
# competitor terms are multiplied together
# in the denominator
with(parms, {
Expand All @@ -22,18 +23,18 @@ model2 <- function(B1, B2, B3, parms ){
})
}

model3 <- function(B1, B2, B3, parms ){
with(parms, {
t1 <- (B1*alpha[1])
t2 <- (B2*alpha[2])
t3 <- (B3*alpha[3])
H1 <- (B1*B2*alpha[1]*alpha[2])
H2 <- (B1*B3*alpha[1]*alpha[3])
H3 <- (B2*B3*alpha[2]*alpha[3])
HOI <- H1+H2+H3
(1/lambda)*(1 + t1 + t2 + t3 + HOI)^tau
})
}
# model3 <- function(B1, B2, B3, parms ){
# with(parms, {
# t1 <- (B1*alpha[1])
# t2 <- (B2*alpha[2])
# t3 <- (B3*alpha[3])
# H1 <- (B1*B2*alpha[1]*alpha[2])
# H2 <- (B1*B3*alpha[1]*alpha[3])
# H3 <- (B2*B3*alpha[2]*alpha[3])
# HOI <- H1+H2+H3
# (1/lambda)*(1 + t1 + t2 + t3 + HOI)^tau
# })
# }

model1_HOI <- function(B1, B2, B3, parms){
# Hassel model with interspecific HOI terms
Expand Down
13 changes: 7 additions & 6 deletions code/plot_fits.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ theme1 <-

xbreaks <- c(0,10,20,30,40)

model_labs <- c('Hassel', 'HOI', 'Model 2')
model_labs <- c('Hassell', 'HOI', 'Multiplicative')

predicted <-
predicted %>%
Expand Down Expand Up @@ -284,12 +284,12 @@ Model2_fits <- two_sp_plot(all_res,
label_df = annotate_df)

Model1_fits <- Model1_fits +
geom_text( data = error2 %>% filter( Model != 'Model 2'),
geom_text( data = error2 %>% filter( Model != 'Multiplicative'),
aes( x = x_pos, y = y_pos,
label = my_expression), hjust = 1, parse = T)

Model2_fits <- Model2_fits +
geom_text( data = error2 %>% filter( Model != 'Hassel'),
geom_text( data = error2 %>% filter( Model != 'Hassell'),
aes( x = x_pos, y = y_pos,
label = my_expression), hjust = 1, parse = T)

Expand Down Expand Up @@ -350,15 +350,16 @@ error_df2 <-
mutate( my_expression = paste0( 'italic(RMSE', '==', RMSE, ')' ))



one2one_plot <-
res %>%
ggplot( aes( x = y_hat, y = y, color = Species)) +
ggplot( aes( x = y, y = y_hat, color = Species)) +
geom_point() +
geom_abline(aes( intercept = 0 , slope = 1)) +
geom_text( data = error_df2, aes( x = pos2, y = pos1, label = my_expression), hjust = 1, parse = T, size = 4.5, color = 1) +
facet_grid( Model ~ Species) +
xlab('Predicted') +
ylab('Observed') +
xlab('Simulated Data') +
ylab('Predicted') +
ggtitle('Focal Species') +
scale_color_manual(values = my_colors[1:3], guide = 'none') +
theme(plot.title = element_text( hjust = 0.5)) +
Expand Down
3 changes: 1 addition & 2 deletions code/plot_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ theme1 <-
strip.text.y = element_blank(),
panel.spacing.y = unit(2, 'lines'))

model_labs <- c('Hassel', 'Model 2', 'HOI')

model_labs <- c('Hassell', 'Multiplicative', 'HOI')

cffs <- lapply( c(fit1, fit2, fit1HOI), coef )

Expand Down
3 changes: 3 additions & 0 deletions code/setup_parms.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,6 @@ seed_label$x_pos <- seed_label$pheno*c(0.6, 1, 1.15)
seed_label$y_pos <- seed_label$max_b*c(1.1, 1.1, 0.9)

mp %>% ggsave( filename = 'figures/example_dynamics_fig3.png', width = 8, height = 6 )


g

0 comments on commit ee137b4

Please sign in to comment.