## Load the Switzerland data
data(Switzerland)
## Summarise the Switzerland data
summary(Switzerland)
## Fit a DI model
m1 <- DI(y = "yield", prop = 4:7, treat = 'nitrogen', DImodel = 'AV',
density = 'density', estimate_theta = TRUE, data = Switzerland)
summary(m1)
## Prediction without newdata, full dataset from model fit will be used
predict(m1, se.fit = TRUE)
## Prediction with newdata
newdata1 <- data.frame('p1' = c(1,0), 'p2' = c(0,1), 'p3' = c(0,0), 'p4' = c(0,0),
'nitrogen' = c(50, 150), 'density' = c('low','high'))
predict(m1, newdata = newdata1, se.fit = TRUE)
## If any categorical variable is missing, the baseline level
## of the variable is used for prediction
newdata2 <- newdata1[, -5]
print(newdata2)
predict(m1, newdata = newdata2)
## If a numerical variable is missing, the value 0 is used for it
newdata3 <- newdata1[, -c(3,4)]
print(newdata3)
predict(m1, newdata = newdata3)
Run the code above in your browser using DataLab