I am trying to plot the significant variable against the probability of conflict (0,1). My Bernoulli #GLM without interaction works without error. My goal is to end with something this but I currently can not get past predicting my values.
#works-expands gird with mean of variables
MyData1 <- expand.grid(Road_density = seq(0, 100, length = 1000),
Livestock_density = 81.98442,
Distance_roads = 3453.99,
Distance_recreational = 7490.875,
Elevation = 379.1109)
#works
X <- model.matrix(~ Livestock_density + Distance_roads + Distance_recreational +
Elevation + Road_density, data = MyData1)
head(MyData1)
coef(Bern3) #output works
#Calculate predicted values for model M1
MyData1$Pred <-X %*% coef(Bern3) #does not work
MyData1$Pred <-coef(Bern3) %*% X #found sugesstion to swap but does not work either
#can not run code below here, due to error- Error in X %*% coef(Bern3) : non-conformable arguments
#Calculate on the predictor scale
MyData1$Pi <- exp(MyData1$Pred) / (1 + exp(MyData1$Pred))
#Calculate standard error spot (SE) for predicted values for model M2
MyData1$se <- sqrt( (X %*% vcov(Bern3) %*% t(X)) )
#Calculate the SEs on the scale of the predictor function
MyData1$SeUp <- exp(MyData1$Pred + 1.96 *MyData1$se) /
(1 + exp(MyData1$Pred + 1.96 *MyData$se))
MyData1$SeLo <- exp(MyData1$Pred - 1.96 *MyData1$se) /
(1 + exp(MyData1$Pred - 1.96 *MyData1$se))