t_test_clustered_stat: t statistic for cluster randomized designs

Description Usage Arguments Value See Also Examples

View source: R/t_test_clustered.R

Description

Calculates the value of a t statistic that has been adjusted for a cluster randomized design. See the vignette "Construction of the library functions" for a description of the assumptions and construction of this t statistic.

Usage

1
t_test_clustered_stat(data_experiment)

Arguments

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 data_experiment.

Value

a number - the value of the cluster adjusted t statistic.

See Also

t_test_clustered_pval for p value of the cluster adjusted t test, power_t_test_clustered for power calculation of the cluster adjusted t test and simulate_power_t_test_clustered for power simulation of the cluster adjusted t test.

Examples

 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
28
29
30
31
#***************************************************************************
# 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 value of the cluster adjusted t statistic on the data_experiment 
# constructed above
# * (since the intracluster correlation coefficient is 0 for this 
#   data_experiment, the cluster adjusted t statistic is actually 
#   unnecessary here...)
t_test_clustered_stat(data_experiment=test_data)
#***************************************************************************

AsgerAndersen/t_test_clustered documentation built on May 17, 2019, 5:41 p.m.