sim <- function(subj_n = 10, item_n = 10,
                b0 = 0, b1 = 0,         # fixed effects 
                u0s_sd = 1, u0i_sd = 1, # random intercepts
                u1i_sd = 1, r01i = 0,   # random slope and cor
                sigma_sd = 2,           # error term
                ... # helps the function work with pmap() below
                ) {

  # set up data structure
  data <- add_random(subj = subj_n, item = item_n) %>%
    # add and recode categorical variables
    add_between("subj", cond = c("control", "test")) %>%
    add_recode("cond", "cond.t", control = 0, test = 1) %>%
    # add random effects 
    add_ranef("subj", u0s = u0s_sd) %>%
    add_ranef("item", u0i = u0i_sd, u1i = u1i_sd, .cors = r01i) %>%
    add_ranef(sigma = sigma_sd) %>%
    # calculate DV
    mutate(dv = b0 + u0s + u0i + (b1 + u1i) * cond.t + sigma)

  # run mixed effect model and return relevant values
  m <- lmer(dv ~ cond.t + (1 | subj) + (1 + cond.t | item), data = data)

  broom.mixed::tidy(m)
}

R相关代码片段

data table remove several columns R

how to reorder x axis labels in r ggplot2

how to open xlsx file in rstudio

how to remove last character in a string r

how to convert character to numeric in r

how to remove na in r

how to use pbbinom in r

unload library in R

convert long to wide in r

how to check r version in cmd

r read mtx

gumboot in r

unload package r

pinstall package in r

extract filename from path in r

Heatmap example

add limit in y axis in r ggplot geom bar

Add character value

Desactivar advertencias R

delete all objects except in R

¬ separator csv file in r

find position in string R

R move column to last using dplyr

Ways to Subset a Data Frame in R

change integer to factor in r

Rename factors levels

how to read a table in r

export excel with multiple sheets in r

Add a color to the bar chart in r language

R pull a vector out of a dataframe

r format of MIPS

Outliers in R

remove text between square brackets

r language gt save as png

R laguage dynamic varible create using for loop

the legend for the bars has points in it (in R)

arrange, filter and select in R

mutate columns in r

summarise number of rows with condition r

link columns titles with underscore in R

group by and count number of rows in r

count rows with condition in r

Count number of element in list R

R progerss: number of iteration replaces itself

save figure in r

nrow with specific value r

getting started with R studio

how to drop nas of an xts object

cross wavelet spectrum in r

plot line segment in multileve bar graph in r

Plot Raster Data in R

wavelet in R

r colorbar

faux package R mixed models

create file r

remove a package R

create data frame easily R

r get max value of column

how to update rlang

smarteda R

how to convert list column to a int column in r

filter by group condition R

scientific notation r

description R

log return calculation in R

how to read a dataset csv file in r

date column to row names R

not regex R stringr

all possible combinations of numbers in r

set a mirror R

if else if r

run after base::.First R

R run after loading base R

R string ends with

R trim stringr

get random lines r

type of var R

dataframe change type R dplyr

How to import data set in R language

calculate mode r