Description Usage Arguments Value See Also Examples
View source: R/t_test_clustered.R
Calculates the p value of a t test that has been adjusted to work in a cluster randomized design. The t test uses the cluster adjusted t statistic, which has a t distribution with the total number of clusters minus 2 degrees of freedom. See the vignette "Construction of the library functions" for a description of the assumptions and construction of the cluster adjusted t statistic and test.
1 2 | t_test_clustered_pval(data_experiment, alternative = c("one.sided",
"two.sided"))
|
data_experiment |
a dataframe with three columns: group, cluster and
response. The response column holds the values of the measured responses. The
group column assigns a group number (must be either 1 or 2) to each
response. The cluster column assigns a cluster number to each response.
Each different cluster must have a different number, even if they are in
different groups. See the examples section for an example of a valid
|
alternative |
has to be set to one of two strings, either
|
a number - the p value of the t test for cluster randomized designs
t_test_clustered_stat
for value of the cluster adjusted
t statistic, power_t_test_clustered
for power calculation of
cluster adjusted t test and simulate_power_t_test_clustered
for power simulation of the cluster adjusted t test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #***************************************************************************
# a valid instance of a data_experiment.
# * this example fits with the underlying model - see XXXX - only in the
# uninteresting case, where the cluster correllation coefficient and the
# treatment effect are both 0
# * although this construction orders the rows of the data.frame according
# to groups and clusters, this ordering does not have to be present for the
# data.frame to be a valid data_experiment
clusters_group_1 <- c(60,50,55)
clusters_group_2 <- c(50,45,50,55)
clusters <- c(clusters_group_1,clusters_group_2)
group_1_size <- sum(clusters_group_1)
group_2_size <- sum(clusters_group_2)
total_size <- group_1_size+group_2_size
group <- as.factor(c(rep(1,group_1_size),rep(2,group_2_size)))
cluster <- vector()
for (i in 1:length(clusters)) {
cluster <- c(cluster,rep(i,clusters[i]))
}
cluster <- as.factor(cluster)
response <- rnorm(total_size)
test_data <- data.frame(group,cluster,response)
#***************************************************************************
#***************************************************************************
# the p value of a two sided cluster adjusted t test
t_test_clustered_pval(test_data,alternative="two.sided")
#***************************************************************************
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.