# mse: mse In baycn: Bayesian Inference for Causal Networks

## Description

Calculates either the edge-wise or whole graph MSE. If more than one data set is input the mean and standard deviation of the MSE will be calculated.

## Usage

 `1` ```mse(posterior, expected, adjMatrix, type = "emse") ```

## Arguments

 `posterior` A list of baycn objects or posterior probability adjacency matrices. Each element in posterior can also be a list. For example, if multiple data sets were generated under the same simulation scheme and baycn was run on each data set, the input list could be a list containing the output from each run of baycn. In this scenario the mean and standard deviation of of the edgewise or whole graph MSE would be output. `expected` The expected edge state probabilities for each edge. This must be a matrix with the expected probability for the three edge states across the columns and each edge down the rows. `adjMatrix` This is only required if the input to posterior is a posterior probability adjacency matrix (for example, output from the BiDAG or structmcmc pacakges). This matrix will be used to convert the posterior probability adjacency matrix to an edge state matrix. Only the edges in adjMatrix will be converted to the edge state matrix. To consider all possible edges use a fully connected adjacency matrix. `type` A character string indicating the type of MSE to be calculated. The two options are 'emse' - edge-wise MSE or 'gmse' - whole graph MSE.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97``` ```set.seed(3) # Generate data from topology M2. data_m2 <- simdata(graph = 'm2_ge', N = 200, b0 = 0, ss = 1, s = 1) # Adjacency matrix for topology M2 am_m2 <- matrix(c(0, 1, 1, 0, 0, 1, 0, 0, 0), byrow = TRUE, nrow = 3) # Run baycn on the data from topology M2. baycn_m2 <- mhEdge(data = data_m2, adjMatrix = am_m2, prior = c(0.05, 0.05, 0.9), nCPh = 0, nGV = 0, pmr = FALSE, iterations = 1000, burnIn = 0.2, thinTo = 500, progress = FALSE) # Expected probabilities for topology M2. ep_m2 <- matrix(c(1, 0, 0, 0, 0, 1, 0, 1, 0), byrow = TRUE, ncol = 3) # Calculate the edgewise MSE. emse_m2 <- mse(posterior = list(baycn_m2), expected = ep_m2, type = 'emse') # When a list with two levels is passed posterior the mean and standard # deviation of the MSE is returned. Below is an example demonstrating this # feature. # Adjacency matrix for topology M2 am_m2 <- matrix(c(0, 1, 1, 0, 0, 1, 0, 0, 0), byrow = TRUE, nrow = 3) # Create a list to hold multiple M2 data sets. data_m2 <- vector(mode = 'list', length = 5) # Create a list to hold the output from baycn. baycn_m2 <- vector(mode = 'list', length = 5) for (e in 1:5) { # Generate data for topology M2. data_m2[[e]] <- simdata(graph = 'm2_ge', N = 200, b0 = 0, ss = 1, s = 1) # Run baycn on the data simulated for topology M2. baycn_m2[[e]] <- mhEdge(data = data_m2[[e]], adjMatrix = am_m2, prior = c(0.05, 0.05, 0.9), nCPh = 0, nGV = 0, pmr = FALSE, iterations = 1000, burnIn = 0.2, thinTo = 500, progress = FALSE) } # Expected probabilities for topology M2. ep_m2 <- matrix(c(1, 0, 0, 0, 0, 1, 0, 1, 0), byrow = TRUE, ncol = 3) # Calculate the edgewise MSE emse_m2 <- mse(posterior = list(baycn_m2), expected = ep_m2, type = 'emse') ```

baycn documentation built on Aug. 1, 2020, 1:07 a.m.