Skip to content

Commit

Permalink
calculate MSE of conditional edge predictions and compare to max int
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjdenny committed Sep 18, 2016
1 parent 8975a3f commit e9921c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
44 changes: 44 additions & 0 deletions R/conditional_edge_prediction_MSE.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' @title A Function to calcualte Mean Edgewise MSE to evaluate edge predictions.
#' @description Calculates mean edgewise MSE for predicted edge values.
#'
#' @param edge_prediction_results A list object returned by the
#' `conditional_edge_prediction()` function.
#' @return A list of MSE's.
#' @export
conditional_edge_prediction_MSE <- function(
edge_prediction_results) {

cur <- edge_prediction_results$max_ent_edge_predictions[,,1]
# calculate average MSE
dimensions <- ncol(cur)
mses <- matrix(NA, ncol = dimensions, nrow = dimensions)
mses_max_ent <- mses
obv <- edge_prediction_results$observed_network

for (i in 1:dimensions) {
for (j in 1:dimensions) {
if (i != j) {
cur <- edge_prediction_results$edge_predictions[i,j,]
cur2 <- edge_prediction_results$max_ent_edge_predictions[i,j,]
mses[i,j] <- mean((cur - obv[i,j])^2)
mses_max_ent[i,j] <- mean((cur2 - obv[i,j])^2)
}
}
}

mse_predicted <- mean(c(mses), na.rm = TRUE)
mse_max_ent <- mean(c(mses_max_ent), na.rm = TRUE)

mse1 <- round(mse_predicted,4)
mse2 <- round(mse_max_ent,4)
cat("Mean MSE for Predicted Edge Values:", mse1,"\n")
cat("Mean MSE for Max Ent Predicted Edge Values:", mse2,"\n")

reduction <- (1 - mse1/mse2)
cat("This represents a",round(reduction*100,2),
"percent reduction in the average edgewise MSE when using the GERGM model.\n")

return(list(model_prediction_average_MSE = mse1,
max_ent_prediction_average_MSE = mse2))
}

19 changes: 19 additions & 0 deletions man/conditional_edge_prediction_MSE.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9921c0

Please sign in to comment.