covarTest_mean: Testing for balanced covariates: equality of means with...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/covarTests.R

Description

Tests equality of means by a t-test for each covariate, between the two full groups or around the discontinuity threshold

Usage

 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
covarTest_mean(
  object,
  bw = NULL,
  paired = FALSE,
  var.equal = FALSE,
  p.adjust = c("none", "holm", "BH", "BY", "hochberg", "hommel", "bonferroni")
)

## S3 method for class 'rdd_data'
covarTest_mean(
  object,
  bw = NULL,
  paired = FALSE,
  var.equal = FALSE,
  p.adjust = c("none", "holm", "BH", "BY", "hochberg", "hommel", "bonferroni")
)

## S3 method for class 'rdd_reg'
covarTest_mean(
  object,
  bw = NULL,
  paired = FALSE,
  var.equal = FALSE,
  p.adjust = c("none", "holm", "BH", "BY", "hochberg", "hommel", "bonferroni")
)

Arguments

object

object of class rdd_data

bw

a bandwidth

paired

Argument of the t.test function: logical indicating whether you want paired t-tests.

var.equal

Argument of the t.test function: logical variable indicating whether to treat the two variances as being equal

p.adjust

Whether to adjust the p-values for multiple testing. Uses the p.adjust function

Value

A data frame with, for each covariate, the mean on each size, the difference, t-stat and ts p-value.

Author(s)

Matthieu Stigler <Matthieu.Stigler@gmail.com>

See Also

covarTest_dis for the Kolmogorov-Smirnov test of equality of distribution

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(house)

## Add randomly generated covariates
set.seed(123)
n_Lee <- nrow(house)
Z <- data.frame(z1 = rnorm(n_Lee, sd=2), 
                z2 = rnorm(n_Lee, mean = ifelse(house<0, 5, 8)), 
                z3 = sample(letters, size = n_Lee, replace = TRUE))
house_rdd_Z <- rdd_data(y = house$y, x = house$x, covar = Z, cutpoint = 0)

## test for equality of means around cutoff:
covarTest_mean(house_rdd_Z, bw=0.3)

## Can also use function covarTest_dis() for Kolmogorov-Smirnov test:
covarTest_dis(house_rdd_Z, bw=0.3)

## covarTest_mean works also on regression outputs (bw will be taken from the model)
reg_nonpara <- rdd_reg_np(rdd_object=house_rdd_Z)
covarTest_mean(reg_nonpara)

Example output

Loading required package: AER
Loading required package: car
Loading required package: carData
Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: survival
Loading required package: np
Nonparametric Kernel Methods for Mixed Datatypes (version 0.60-9)
[vignette("np_faq",package="np") provides answers to frequently asked questions]
[vignette("np",package="np") an overview]
[vignette("entropy_np",package="np") an overview of entropy-based methods]
   mean of x   mean of y Difference statistic  p.value  
z1 0.004268177 0.0218581 0.01758993 -0.2539109 0.7995803
z2 5.005608    7.984865  2.979257   -84.84982  0        
z3 13.18888    13.43534  0.2464617  -0.9409715 0.3467888
   statistic  p.value  
z1 0.03482029 0.2726692
z2 0.8647849  0        
z3 0.03008545 0.447416 
Warning message:
In ks.test(x[regime], x[!regime], exact = exact) :
  p-value will be approximate in the presence of ties
   mean of x    mean of y  Difference statistic  p.value  
z1 -0.009705805 0.03187163 0.04157744 -0.5931762 0.5531052
z2 5.007297     7.981714   2.974417   -83.8092   0        
z3 13.20138     13.48257   0.2811852  -1.060392  0.2890465

rddtools documentation built on Jan. 10, 2022, 5:07 p.m.