library(DImodels)
## Load data
data(sim2)
## Fit model
mod <- glm(response ~ (p1 + p2 + p3 + p4)^2 + 0, data = sim2)
## Create data for visualising change in response as we move from
## a species dominated by 70% of one species to a monoculture of
## same species
head(simplex_path_data(starts = sim2[c(1, 5, 9, 13), 3:6],
ends = sim2[c(48, 52, 56, 60), 3:6],
prop = c("p1", "p2", "p3", "p4"),
model = mod))
## Create data for visualising change in response as we move from
## the centroid mixture to each monoculture
## If either of starts or ends have only row, then they'll be recycled
## to match the number of rows in the other
## Notice starts has only one row here, but will be recycled to have 4
## since ends has 4 four rows
head(simplex_path_data(starts = sim2[c(18),3:6],
ends = sim2[c(48, 52, 56, 60),3:6],
prop = c("p1", "p2", "p3", "p4"),
model = mod))
## Changing the confidence level for the prediction interval
## Use `conf.level` parameter
head(simplex_path_data(starts = sim2[c(18), 3:6],
ends = sim2[c(48, 52, 56, 60),3:6],
prop = c("p1", "p2", "p3", "p4"),
model = mod, conf.level = 0.99))
## Adding additional variables to the data using `add_var`
## Notice the new .add_str_ID column in the output
sim2$block <- as.numeric(sim2$block)
new_mod <- update(mod, ~ . + block, data = sim2)
head(simplex_path_data(starts = sim2[c(18), 3:6],
ends = sim2[c(48, 52, 56, 60), 3:6],
prop = c("p1", "p2", "p3", "p4"),
model = new_mod, conf.level = 0.99,
add_var = list("block" = c(1, 2))))
## Use predict = FALSE to get raw data structure
out_data <- simplex_path_data(starts = sim2[c(18), 3:6],
ends = sim2[c(48, 52, 56, 60), 3:6],
prop = c("p1", "p2", "p3", "p4"),
model = new_mod,
prediction = FALSE)
head(out_data)
## Manually add block
out_data$block = 3
## Call `add_prediction` to get prediction
head(add_prediction(data = out_data, model = new_mod, interval = "conf"))
Run the code above in your browser using DataLab