as.matrix.coef_diff_by_group_stan: S3 as.matrix for result of coef_diff_by_group

Description Usage Arguments Value Examples

View source: R/as_matrix_coef_diff_by_group_stan.R

Description

Generates a matrix that can be used with plotting functions from package MCMC-distributions.

Usage

1
2
## S3 method for class 'coef_diff_by_group_stan'
as.matrix(x, ...)

Arguments

x

Result of a call to coef_diff_by_group(fit)

...

parameter name as string, e.g. "m", "k", "beta", "t50_bluck_coward". When missing, "t50_maes_ghoos" is assumed.

Value

mcmc array with columns of differences for use with functions from packages bayesplot or coda

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(dplyr)
library(breathtestcore)
library(ggplot2)
data("usz_13c", package = "breathtestcore")
data = usz_13c %>%
  dplyr::filter( patient_id %in%  c("norm_001", "norm_002", "norm_003",
                        "norm_004", "pat_001", "pat_002","pat_003")) %>%
  cleanup_data()
fit = stan_group_fit(data, iter = 300, chains = 1)
cf = coef_diff_by_group(fit)
str(cf)
# Calling without parameters gives Maes/Ghoos t50
bayesplot::mcmc_hist(as.matrix(cf))
# Use a function from the bayesplot universe
dens = bayesplot::mcmc_dens(as.matrix(cf, parameter = "m"))
# use suppressMessages to avoid a message "another scale"
suppressMessages(
  dens + geom_vline(xintercept = 0) + scale_x_continuous(limits= c(-20,10)))

breathteststan documentation built on Oct. 11, 2018, 1:04 a.m.