print_coeff: Prints individual coefficients for RMarkdown inline reporting

Description Usage Arguments Value Examples

View source: R/print_coeff.r

Description

This function takes the output of result_table and transforms it into latex-code to be used in a rmarkdown file. There are two ways to specify which relationship or effect should be printed: 1) If the relationships are labelled in the result table that is passed to the function, the argument var_label can be used to specify which effect should be printed; 2) If the result table does not contain an labels, the argument var_predict can be used to specify the predictor variable of the effect that should be printed. Alternatively, it also takes output of anova_stats and transforms it into latex-code.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
print_coeff(
  object,
  var_label = NULL,
  var_predict = NULL,
  b = TRUE,
  median = TRUE,
  se = TRUE,
  ci = TRUE,
  p = TRUE,
  beta = FALSE,
  anova_effect = NULL
)

Arguments

object

A dataframe resulting from result_table. Important: The dataframe needs to be print-ready (i.e, the argument print = TRUE must be used!).

var_label

A character value indicating which coefficient should be printed (draws from the label column in the dataframe).

var_predict

Predictor variable that should be printed.

b

Should the unstandardized effect be printed?

se

Should the standard error be printed?

ci

Should the confidence intervals (if bayesian: high credibility intervals) be printed?

p

Should the p-value be printed?

beta

Should the standarized coefficient be printed?

anova_effect

Which effect size should be reported (e.g., "cohens.f", "etasq", or "partial.etasq")

Value

A string representing a latex code that can be used in inline reporting in Rmarkdown documents.

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
## Example 1: Reporting effects from a structural equation modelling

library(lavaan)
# Estimate the structural equation model
model <- '
  # latent variables
  ind60 =~ x1 + x2 + x3
  dem60 =~ y1 + y2 + y3 + y4
  dem65 =~ y5 + y6 + y7 + y8
  
  # regressions
  dem60 ~ ind60
  dem65 ~ ind60 + dem60
  
  # residual covariances
  y1 ~~ y5
  y2 ~~ y4 + y6
  y3 ~~ y7
  y4 ~~ y8
  y6 ~~ y8
'
# Fitting model
fit <- sem(model,
           data = PoliticalDemocracy)

# First step (print = TRUE is mandatory!)
results <- result_table(fit, 
                        sem_regressions = TRUE, 
                        new_labels = c("H1", "H2", "H3"), 
                        print = TRUE)

# Second step
print_coeff(results, 
            var_label = "H1")
print_coeff(results, "H2", 
            se = FALSE, 
            beta = TRUE)


## Example 2: Reporting effects from a multilevel model

# Estimate the multilevel model
model <- lmerTest::lmer(Reaction ~ 1 + Days + (1 | Subject), 
                        data = sleepstudy)

# First step (print = TRUE is mandatory!)
results <- result_table(model, print = TRUE)

# Second step
print_coeff(results, 
            var_predict = "Days", 
            ci = FALSE, 
            p = FALSE)


## Example 3: Reporting effects from a Bayesian multilevel model

# Estimate the Bayesian multilevel model (using "brms")
model_bayes <- brms::brm(Reaction ~ 1 + Days + (1 | Subject), 
                         data = sleepstudy,
                         chains = 1)

# First step (print = TRUE is mandatory!)
results_bayes <- result_table(model_bayes, print = TRUE)

# Second step
print_coeff(results_bayes, 
            var_predict = "b_Days")
            
## Example 4: Reporting results from ANOVAs
x <- rep(c(1,0), 50)
y <- 2*x + rnorm(100, 0, 1)

# First step
m <- aov(y ~ x)

# Second step (sjstats::anova_stats() needs to be used)
print_coeff(sjstats::anova_stats(m), 
            var_predict = "x", 
            anova_effect = "etasq")

masurp/pmstats documentation built on Oct. 6, 2020, 9:24 p.m.