# set seed for reproducibility
set.seed(42)
rnorm(n = 10,
mean = 0,
sd = 1) [1] 1.37095845 -0.56469817 0.36312841 0.63286260 0.40426832 -0.10612452
[7] 1.51152200 -0.09465904 2.01842371 -0.06271410
These exercises accompany the Required skills chapter.
Complete the following exercises in your local copy of this .qmd file to check your data tidying skills. Either download a copy of the whole book from github (see introduction), or download this .qmd using the download button on the top right of the page. Most of them involve extracting estimates from objects created by data simulation or statistical modelling functions.
If you need a refresher, see the chapter on tidy data and reshaping in Ian’s other book.
dplyr::summarize().data_intervention data set.dplyr::summarize().data_intervention data set.dplyr::summarize(), group_by() and the pipe (%>% or |>).data_for_ttest data set.dplyr::summarize(), group_by() and the pipe (%>% or |>).data_for_ttest data set.dplyr::summarize(), group_by() and the pipe (%>% or |>).data_for_ttest data set.roundwork::round_up(). Ideally, use mutate_if() or across() to round multiple columns.The rnorm() samples data from a normally distributed population with a given population mean (\(\mu\)) and population standard deviation (\(\sigma\)).
# set seed for reproducibility
set.seed(42)
rnorm(n = 10,
mean = 0,
sd = 1) [1] 1.37095845 -0.56469817 0.36312841 0.63286260 0.40426832 -0.10612452
[7] 1.51152200 -0.09465904 2.01842371 -0.06271410
Make this tidier by returning this simulated values as the column score in a tibble. Assign the tibble to the object data_control.
Create a second object, data_intervention, where the observations are sampled from a population mean (\(\mu\)) of 0.4.
Create a new column called condition in each tibble using the appropriate {dplyr} function, setting it to “control” and “intervention” in the respective tibbles.
Create a new object, data_rct, from data_control and data_intervention by binding the two tibbles together using the appropriate {dplyr} bind_ function.
data_for_ttest data set.effectsize::cohens_d() and extract the Cohen’s d estimate and its 95% CIs.data_for_ttest data set.d_estimate, d_ci_lower, d_ci_upperFit a correlation test using cor.test() and extract the correlation estimate.
data_for_correlation data set.Extract the p-value from correlation test
data_for_correlation data set.Extract both the correlation and the p value
data_for_correlation data set.