The present script can be used to pre-process data from a frequency list of the Norwegian as Web Corpus (NoWaC).
Before using the script, the frequency list should be downloaded from https://www.hf.uio.no/iln/english/about/organization/text-laborat... [Read more...]

The R package simr has greatly facilitated power analysis for mixed-effects models using Monte Carlo simulation (i.e., hundreds or thousands of tests under slight variations of the data). The powerCurve function is used to estimate the statistical power for various sample sizes in one go. Since it runs serially, ...

[Read more...] Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot (Lüdecke, 2022). For instance, using the plot_model function, I plotted the interaction between two continuous variables.

[Read more...]library(lme4) #> Loading required package: Matrix library(sjPlot) library(ggplot2) theme_set(theme_sjplot()) # Create data using code by Ben Bolker from # https://stackoverflow.com/a/38296264/7050882 set.seed(101) spin = runif(600, 1, 24) reg = runif(600, 1, 15) ID = rep(c("1","2","3","4","5", "6", "7", "8", "9", "10")) day = rep(1:30, each = 10) testdata <- data.frame(spin, reg, ID, day) testdata$fatigue <- testdata$spin * testdata$reg/10 * rnorm(30, mean=3, sd=2) fit = lmer(fatigue ~ spin * reg + (1|ID), data = testdata, REML = TRUE) plot_model(fit, type = 'pred', terms = c('spin', 'reg')) #> Warning: Ignoring unknown parameters: linewidth...

Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot (Lüdecke, 2022). For instance, using the plot_model function, I plotted the interaction between two continuous variables.

[Read more...]library(lme4) #> Loading required package: Matrix library(sjPlot) #> Learn more about sjPlot with 'browseVignettes("sjPlot")'. library(ggplot2) theme_set(theme_sjplot()) # Create data partially based on code by Ben Bolker # from https://stackoverflow.com/a/38296264/7050882 set.seed(101) spin = runif(800, 1, 24) trait = rep(1:40, each = 20) ID = rep(1:80, each = 10) testdata <- data.frame(spin, trait, ID) testdata$fatigue <- testdata$spin * testdata$trait / rnorm(800, mean = 6, sd = 2) # Model fit = lmer(fatigue ~ spin * trait + (1|ID), data = testdata, REML = TRUE) #> boundary (singular) fit: see help('isSingular') plot_model(fit, type = 'pred', terms = c('spin', 'trait')) #> Warning: Ignoring unknown parameters: linewidth...

Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot (Lüdecke, 2022). For instance, using the plot_model function, I plotted the interaction between a continuous variable and ...

[Read more...] To assess whether convergence warnings render the results invalid, or on the contrary, the results can be deemed valid in spite of the warnings, Bates et al. (2023) suggest refitting models affected by convergence warnings with a variety of optimizers. The authors argue that, if the different optimizers produce practically-equivalent results, ...

[Read more...]Here’s an example of fuzzy-matching strings in R that I shared on StackOverflow. In stringdist_join, the max_dist argument is used to constrain the degree of fuzziness.

library(fuzzyjoin) library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union library(knitr) small_tab = data.frame(Food.Name = c('Corn', 'Squash', 'Peppers'), Food.Code = c(NA, NA, NA)) large_tab = data.frame(Food.Name = c('Sweet Corn', 'Red Corn', 'Baby Corns', 'Squash', 'Long Squash', 'Red Pepper', 'Green Pepper', 'Red Peppers'), Food.Code = c(532, 532, 944, 111, 123, 654, 655, 654)) joined_tab = stringdist_join(small_tab, large_tab, by = 'Food.Name', ignore_case = TRUE, method = 'cosine', max_dist = 0.5, distance_col = 'dist') %>% # Tidy columns select(Food.Name = Food.Name.x, -Food.Name.y, Food.Code = Food.Code.y, -dist) %>% # Only keep most frequent food code per food name group_by(Food.Name) %>% count(Food.Name, Food.Code) %>% slice(which.max(n)) %>% select(-n) %>% # Order food names as in the small table arrange(factor(Food.Name, levels = small_tab$Food.Name)) # Show table with columns renamed joined_tab %>% rename('Food Name' = Food.Name, 'Food Code' = Food.Code) %>% kable()Food Name Food Code Corn 532 Squash 111 Peppers 654 Created on 2023-05-31 with reprex v2.0.2 [Read more...]

Linear mixed-effects models (LMM) offer a consistent way of performing regression and analysis of variance tests which allows accounting for non-independence in the data. Over the past decades, LMMs have subsumed most of the General Linear Model, with a steady increase in popularity (Meteyard & Davies, 2020). Since their conception, LMMs have ...

[Read more...]
Here I share the format applied to tables presenting the results of frequentist models in Bernabeu (2022; the table for Bayesian models is covered in this other post). The sample table presents a mixed-effects model that was fitted using the R package lmerTest (Kuznetsova et al., 2022). The mixed effects were driven ... [Read more...]

Here I share the format applied to tables presenting the results of Bayesian models in Bernabeu (2022; the table for frequentist models is covered in this other post). The sample table presents a Bayesian mixed-effects model that was fitted using the R package brms (Bürkner et al., 2022). The mixed effects ... [Read more...]

Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot (Lüdecke, 2022). In Bernabeu (2022), the sjPlot ... [Read more...]

Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot (Lüdecke, 2022). In Bernabeu (2022), the sjPlot ...

[Read more...]
Frequentist and Bayesian statistics are sometimes regarded as fundamentally different philosophies. Indeed, can both methods qualify as philosophies, or is one of them just a pointless ritual? Is frequentist statistics about \(p\) values only? Are frequentist estimates diametrically opposed to Bayesian posterior distributions? Are confidence intervals and credible intervals irreconcilable? ...

[Read more...]
Frequentist and Bayesian statistics are sometimes regarded as fundamentally different philosophies. Indeed, can both methods qualify as philosophies, or is one of them just a pointless ritual? Is frequentist statistics about \(p\) values only? Are frequentist estimates diametrically opposed to Bayesian posterior distributions? Are confidence intervals and credible intervals irreconcilable? ...

[Read more...]
This post presents a code-through of a Bayesian workflow in R, which can be reproduced using the materials at https://osf.io/gt5uf. The content is closely based on Bernabeu (2022), which was in turn based on lots of other references. In addition to those, you may wish to consider ...

[Read more...]
Reference
Bernabeu, P., Lynott, D., & Connell, L. (2022). Language and vision in conceptual processing: Multilevel analysis and statistical power. OSF. https://osf.io/dnskh
[Read more...]

Reference
Bernabeu, P. (2022). Language and sensorimotor simulation in conceptual processing: Multilevel analysis and statistical power. Lancaster University. https://doi.org/10.17635/lancaster/thesis/1795
[Read more...]

The function knit-deleting-service-files() is designed to avoid (R) Markdown knitting errors caused by service files from previous knittings (e.g., manuscript.tex, ZHJhZnQtYXBhLlJtZA==.Rmd, manuscript.synctex.gz). The function first suggests deleti...

[Read more...]
As technology and research methods advance, the data sets tend to be larger and the methods more exhaustive. Consequently, the analyses take longer to run. This poses a challenge when the results are to be presented using R Markdown. One has to walk the line between reproducibility and efficiency. On ... [Read more...]

When knitting an R Markdown document after the first time, errors may sometimes appear. Three tips are recommended below.
1. Close PDF reader window
When the document is knitted through the ‘Knit’ button, a PDF reader window opens to present the result. Closing this window can help resolve knitting errors.
2. Delete ... [Read more...]

Copyright © 2023 | MH Corporate basic by MH Themes

e-mails with the latest R posts.

(You will not see this message again.)