## Load the Switzerland data
data(Switzerland)
## View the first few entries
head(Switzerland)
## Explore the variables in Switzerland
str(Switzerland)
## Histogram of the response variable yield
hist(Switzerland$yield)
## Explore the marginal relationship between yield and each predictor
plot(Switzerland$p1, Switzerland$yield)
plot(Switzerland$p2, Switzerland$yield)
plot(Switzerland$p3, Switzerland$yield)
plot(Switzerland$p4, Switzerland$yield)
boxplot(yield ~ nitrogen, data = Switzerland)
boxplot(yield ~ density, data = Switzerland)
## Check that the proportions sum to 1 (required for DI models)
## p1 to p4 are in the 4th to 7th columns in Switzerland
Switzerlandsums <- rowSums(Switzerland[4:7])
summary(Switzerlandsums)
## Model selection by F-test
auto1 <- autoDI(y = "yield", density = "density", prop = c("p1","p2","p3","p4"),
treat = "nitrogen", FG = c("G","G","L","L"), data = Switzerland,
selection = "Ftest")
summary(auto1)
## Fit the model chosen by autoDI using DI
m1 <- DI(y = "yield", density = "density", prop = 4:7, DImodel = "FG", FG = c("G","G","L","L"),
data = Switzerland)
summary(m1)
plot(m1)
# \donttest{
## Check goodness-of-fit using a half-normal plot with a simulated envelope
library(hnp)
hnp(m1)
# }
## Set up the functional group interactions and add to a new Switzerland2 dataset
FG_matrix <- DI_data(prop = 4:7, FG = c("G","G","L","L"),
data = Switzerland, what = "FG")
Switzerland2 <- data.frame(Switzerland, FG_matrix)
## Additional model testing using DI to test for interactions with nitrogen
m2 <- DI(y = "yield", block = "density", prop = 4:7, DImodel = "FG", FG = c("G","G","L","L"),
data = Switzerland2, extra_formula = ~ nitrogen:bfg_G_L)
summary(m2)
Run the code above in your browser using DataLab