-
Notifications
You must be signed in to change notification settings - Fork 3
/
print.meta_stan.R
81 lines (71 loc) · 2.18 KB
/
print.meta_stan.R
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
#' Print meta_stan object
#'
#' Takes an \code{meta_stan} object which is obtained by function \code{meta_stan} and print
#' the model and data information such as model type used in the model.
#'
#'
#' @param x A \code{meta_stan} object.
#' @param digits An integer indicating the number of decimal places.
#' @param ... Further arguments passed to or from other methods.
#' @return The return value is invisible \code{NULL}
#' @export
print.meta_stan <- function(x, digits = 2, ...) {
if (!is.element("meta_stan", class(x)))
stop("Argument 'x' must be an object of class \"meta_stan\".")
cat("Meta-analysis using MetaStan \n\n")
cat("Maximum Rhat:", signif(x$Rhat.max, digits=3),"\n")
cat("Minimum Effective Sample Size:", signif(x$N_EFF.min, digits=digits),"\n\n")
cat("mu prior: Normal")
cat("(")
cat(x$stanDat$mu_prior[1])
cat(",")
cat(x$stanDat$mu_prior[2])
cat(")")
cat("\n")
cat("theta prior: Normal")
cat("(")
cat(x$stanDat$theta_prior[1])
cat(",")
cat(round(x$stanDat$theta_prior[2], 2))
cat(")")
cat("\n")
if (x$stanDat$mreg){
cat("beta prior: Normal")
cat("(")
cat(x$stanDat$beta_prior[1])
cat(",")
cat(x$stanDat$beta_prior[2])
cat(")")
cat("\n")
}
if (x$stanDat$re){
cat("tau prior:")
cat(x$tau_prior_dist)
cat("(")
cat(x$stanDat$tau_prior)
cat(")")
cat("\n\n")
}
cat("Treatment effect (theta) estimates\n")
print(round(x$fit_sum['theta', -c(2, 3, 5, 7, 9, 10)], digits))
cat("\n")
if (x$stanDat$mreg){
cat("Beta coeffients\n")
print(round(x$fit_sum['beta[1,1]', -c(2, 3, 5, 7, 9, 10)], digits))
cat("\n")
}
if (x$stanDat$re){
cat("Heterogeneity stdev (tau)\n")
if (x$interval.type == "shortest"){
mcmc = coda::mcmc.list(rstan::As.mcmc.list(x$fit, pars = c("tau[1]")))
tau_int = HDInterval::hdi(mcmc, credMass = 0.95)
temp = matrix(round(c(x$fit_sum['tau[1]', 1], tau_int[1],
x$fit_sum['tau[1]', "50%"], tau_int[2]), digits), ncol = 4)
colnames(temp) = c("Mean", "Lower", "50%", "Upper")
print(temp)
} else {
print(round(x$fit_sum['tau[1]', -c(2, 3, 5, 7, 9, 10)], digits))
}
}
return(invisible())
}