t_test_clustered_pval: p value of the t test for cluster randomized designs

Description Usage Arguments Value See Also Examples

Description

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.

Usage

1
2
t_test_clustered_pval(data_experiment, alternative = c("one.sided",
  "two.sided"))

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.

alternative

has to be set to one of two strings, either "one.sided" or "two.sided", to say whether the alternative hypothesis is one-sided or two-sided.

Value

a number - the p value of the t test for cluster randomized designs

See Also

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.

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
#***************************************************************************
# 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")
#***************************************************************************

AsgerAndersen/t.test.clustered documentation built on May 5, 2019, 8:12 a.m.