You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library(dplyr)
library(tidyverse)
set.seed(54321) # setting the seed to a specific number will result in reproducible random numbers
N = 40
# First, we create a set of vectors of length N=40 and fill them with numbers sampled from a normal distribution using rnorm():
c1 <- rnorm(N, mean = 100, sd = 25) # we will use these numbers as our control group 1
#g1 <- rnorm(N, mean = 120, sd = 25) # we will use these numbers as our experimental group 1
g1 <- c1 + 2 + rnorm(N, mean = 0.1, sd = 0.01)
gender <- c(rep('Male', N/2), rep('Female', N/2))
id <- 1: N
# Here we create a data frame, which includes all vectors (like a table) :
wide_data <-
tibble(
Control1 = c1,
Group1 = g1,
Gender = gender, ID = id)
View(wide_data)
# Next we reformat the data, so that the data points are stored as one long column vector and the
# group assignment and the gender is stored in a long column vector as well.
# This is the format we need for using the dabest() function (Note: dabest is an abbreviation for
# Data Analysis with Bootstrap-coupled ESTimation )
my_data <-
wide_data %>%
gather(key = Group, value = Measurement, -ID, -Gender)
View(my_data)
library(dabestr)
two.groups.unpaired <-
dabest(my_data, Group, Measurement,
idx = c("Control1", "Group1"),
paired = FALSE)
# plot(mean_diff(two.groups.unpaired), color.column = Gender)
plot(cohens_d(two.groups.unpaired), color.column = Gender) # Cohen's d and Hedge's g (see next
# line) are standardized effect sizes. They normalize the mean difference by the
# pooled standard deviation.
# Create paired plots:
two.groups.paired <-
dabest(my_data, Group, Measurement,
idx = c("Control1", "Group1"),
paired = TRUE, id.col = ID) # the ID provides the information about which samples are paired
# plot(mean_diff(two.groups.paired), color.column = Gender)
two.groups.paired %>%
cohens_d() %>%
plot(color.column = Gender)
However, the visualization of the effect size does not change despite I set "paired" to TRUE. Am I missing a trick?
Many thanks,
Petra
The text was updated successfully, but these errors were encountered:
Thanks a lot, Jose.
If I install the version, I suddenly get issues with multiplots.
E.g. when using:
multi.group <-
my_data %>%
dabest(Group, Measurement,
idx = list(c("Control1", "Group1", "Group3"),
c("Control2", "Group2", "Group4")),
paired = FALSE
)
multi.group.mean_diff <- multi.group %>% mean_diff()
The scatter points turn into straight lines.
If I simply update to the latest developer version
devtools::install_github("ACCLAB/dabestr"), then the multi-plot looks fine again, but the CIs for the paired comparison are again wrong.
Is there any way to update the version so that both functionalities work?
Hello,
I adapted the code from https://cran.r-project.org/web/packages/dabestr/vignettes/using-dabestr.html
to show how the effect size should become much more precise (i.e. the distribution should become much more narrow) when using a paired comparison with my artificial data.
However, the visualization of the effect size does not change despite I set "paired" to TRUE. Am I missing a trick?
Many thanks,
Petra
The text was updated successfully, but these errors were encountered: