summary-mcmcabn.R 1.66 KB
Newer Older
Gilles Kratzer's avatar
Gilles Kratzer committed
1
2
3
############################################################################### summary.mcmcabn.R --- Author : Gilles Kratzer Last modified : 19.02.2019 :

summary.mcmcabn <- function(object, quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975), lag.max = 10, ...) {
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
4

Gilles Kratzer's avatar
Gilles Kratzer committed
5
    cat("MCMC summary:\n", sep = "")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
6

Reinhard Furrer's avatar
details    
Reinhard Furrer committed
7
    cat("Number of burn-in steps: ", (object$burnin), "\n", sep = "")
Gilles Kratzer's avatar
Gilles Kratzer committed
8
9
    cat("Number of MCMC steps: ", (object$iterations), "\n", sep = "")
    cat("Thinning: ", (object$thinning), "\n\n", sep = "")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
10

Gilles Kratzer's avatar
Gilles Kratzer committed
11
12
    cat("Maximum score: ", max(object$scores), "\n", sep = "")
    cat("Empirical mean: ", mean(object$scores), "\n", sep = "")
Reinhard Furrer's avatar
details    
Reinhard Furrer committed
13
    cat("Empirical standard deviation: ", format(sd(object$scores),...), "\n", sep = "")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
14

Gilles Kratzer's avatar
Gilles Kratzer committed
15
    cat("Quantiles of the posterior network score:\n")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
16
17

    out1 <- matrix(data = quantile(x = object$scores, probs = quantiles), nrow = 1, ncol = length(quantiles), dimnames = list("BN score",
Gilles Kratzer's avatar
Gilles Kratzer committed
18
        quantiles))
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
19

Gilles Kratzer's avatar
Gilles Kratzer committed
20
    print(out1, ...)
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
21

Reinhard Furrer's avatar
details    
Reinhard Furrer committed
22
    cat("\n\nGlobal acceptance rate: ", format( 1 - mean(object$rejection), ...), "\n", sep = "")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
23
24

    out2 <- matrix(data = table(object$method, object$rejection), ncol = 2, dimnames = list(levels(factor(object$method)),
Gilles Kratzer's avatar
Gilles Kratzer committed
25
        c("Accepted", "Rejected")))
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
26

Gilles Kratzer's avatar
Gilles Kratzer committed
27
    print(out2, ...)
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
28

Reinhard Furrer's avatar
details    
Reinhard Furrer committed
29
30
    cat("\n\nSample size adjusted for autocorrelation: ",
        format( unname(effectiveSize(object$scores)), ...), "\n", sep = "")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
31

Reinhard Furrer's avatar
details    
Reinhard Furrer committed
32
#    unname(acf(object$scores, lag.max = 10, plot = FALSE))
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
33
34


Gilles Kratzer's avatar
Gilles Kratzer committed
35
    cat("\nAutocorrelations by lag:\n")
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
36
37

    out2 <- matrix(data = acf(object$scores, lag.max = 10, plot = FALSE)$acf, nrow = 1, ncol = (lag.max + 1), dimnames = list("acf",
Gilles Kratzer's avatar
Gilles Kratzer committed
38
        acf(object$scores, lag.max = 10, plot = FALSE)$lag))
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
39

Gilles Kratzer's avatar
Gilles Kratzer committed
40
    print(out2, ...)
Gilles Kratzer's avatar
typos    
Gilles Kratzer committed
41

Gilles Kratzer's avatar
Gilles Kratzer committed
42
}  #EOF