I'm going to create a series of table
library(sjPlot)
tables_models <- lapply(models_list_2, tab_model, show.ci = FALSE,
show.se = TRUE,
show.p = TRUE,
show.stat = TRUE,
show.df = TRUE,
show.ngroups = TRUE,
digits = 4,
digits.p = 3,
digits.re = 3,
**title = title**,
string.pred = "Predictors",
string.est = "Estimate",
string.se = "std. Error",
string.p = "Pr(>|t|)",
string.df = "df",
string.stat = "t-value",
string.intercept = "(Intercept)",
df.method = 'kr',
p.val = 'kr',
p.style = 'numeric_stars') %>%
setNames(sort(unique(out_long$signals)))
Where the title input should assign a title like 'Description of....' and then proper related signals' names which it represents:
title <- c(
'X1F7', 'X1C1', 'X1P1',
'YearlyF7', 'YearlyC1', 'YearlyP1',
'Y1F7', 'Y1C1', 'Y1P1',
'Y2F7', 'Y2C1', 'Y2P1',
'Y2PO3'
)
How should I set out the title input
for assign each name reported into the title object for a different table?
Thanks for paying attention
Here the dataset I'm working
structure(list(
subj = rep(c("Z01", "Z04", "Z06", "Z07", "Z08", "Z09", "Z10", "Z11", "Z12", "Z13"), each = 3),
cluster = rep("XG", 30),
type = rep("M", 30),
condition = rep(c("POS-EXP", "POS-CTRL", "CTRL-VAL"), 10),
channel = factor(rep("X1F7", 30), levels = c("X1F7", "X1C1", "X1P1", "YearlyF7", "YearlyC1", "YearlyP1", "Y1F7", "Y1C1", "Y1P1", "Y2F7", "Y2C1", "Y2P1", "Y2PO3")),
response = round(rnorm(30, mean = 0, sd = 5), 3)
), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -30L))
and the commands lines which I fitted the model through (because these are tables showing model output)
library(lme4)
library(dplyr)
models_list_2 <- out_long %>%
group_by(channel) %>%
do(fit = lmerTest::lmer(response ~ condition + (1|subj), data = .)) %>%
pull(fit)
Using mapply
in case where we would want apply
but on multiple lists/vectors (i.e. one list has models and another the titles we want to use:)
From ?mapply
:
mapply is a multivariate version of sapply. mapply applies FUN to the first elements of each ... argument, the second elements, the third elements, and so on. Arguments are recycled if necessary.
models <- 1:4
titles <- paste0("Desc of ", models)
dummy_fun <- function(x, y, other1, other2) return(paste0(x, y, other1, other2))
We pass the two (ore more) equal length vectors as unnamed arguments, FUN takes the function we want to apply and all other (constant) arguments we want to pass to FUN go packet into a list into MoreArgs
mapply(models, titles, FUN = dummy_fun, MoreArgs = list(other1 = "a", other2 = "b"))