Skip to contents

Trend test

The trend() function carries out a chi-squared test for trend (on 1 degree of freedom) on a vector of independent estimates. The function arguments are a vector beta of independent estimates and a vector se of their standard errors. The function returns the test statistic and p-value in a named list.

Example

These data are taken from Figure 3 of the paper ‘Fresh fruit consumption and major cardiovascular disease in the China Kadoorie Biobank’ by Du, H., Li, L., Bennett, D. et al. N Engl J Med 2016; 374: 1332–1343.

b <- c(-0.59784, -0.28768, -0.4943)
s <- c(0.127929, 0.121515, 0.094959)

trend(b, s)
# $`test statistic`
# [1] 0.1386369
# 
# $p
# [1] 0.7096399

Heterogeneity test

The heterogeneity() function carries out a a chi-squared test (on k1k - 1 degrees of freedom) for heterogeneity on a vector of kk independent estimates. The function arguments are a vector beta of independent estimates and a vector se of their standard errors. The function returns the test statistic, degrees of freedom and p-value in a named list.

Example

These data are taken from Figure 3 of Du et al.

beta <- c(-0.47804, -0.46204, -0.40048)
se <- c(0.090005, 0.176823, 0.106565)

heterogeneity(beta, se)
# $`test statistic`
# [1] 0.3165459
# 
# $`degrees of freedom`
# [1] 2
# 
# $p
# [1] 0.8536168

Methods

Trend

Suppose that we want to check whether estimates change progressively from one stratum (subgroup) to the next then we could use a chi-squared test for trend (on 1 degree of freedom).

The test statistic for trend given a vector of kk independent estimates β̂i\hat{\beta}_i and their standard errors σi\sigma_i is

i=1k(wiβ̂i(iA))2i=1kwi(iA)2 \frac{\sum_{i = 1}^{k} \left(w_i \hat{\beta}_i (i - A) \right)^2}{\sum_{i = 1}^{k}{w_i (i - A)^2}} where

A=j=1kjwjj=1kwjA = \frac{\sum_{j = 1}^{k}{j w_j}}{\sum_{j = 1}^{k}{w_j}}

and wi=1/σ2w_i = 1/\sigma^2. This test statistic has a chi-squared distribution with 1 degree of freedom under the null hypothesis of no linear trend.

Heterogeneity

Suppose that information on the estimates for different strata (subgroups) are to be assessed in order to see if they differ between strata (i.e. effect modification) then a chi-squared test (on k1k - 1 degrees of freedom) for heterogeneity between the estimates for the different strata can used.

The test statistic for heterogeneity given a vector of kk independent estimates β̂i\hat{\beta}_i and their standard errors σi\sigma_i is

(i=1kwiβ̂i2)(i=1kwiβ̂i)2i=1kwi, \left(\sum_{i=1}^{k} w_i \hat{\beta}_i^2 \right) - \frac{\left(\sum_{i=1}^{k} w_i \hat{\beta}_i \right)^2}{\sum_{i=1}^{k} w_i},

where wi=1/σ2w_i = 1/\sigma^2, which has a chi-squared distribution with k1k-1 degrees of freedom under the null hypothesis.

The test statistic can also be written as:

i=1k[wi(β̂ij=1kwjβ̂jj=1kwj)2] \sum_{i=1}^{k} \left[ w_i \left( \hat{\beta}_i - \frac{\sum_{j=1}^{k} w_j\hat{\beta}_j}{\sum_{j=1}^{k} w_j} \right)^2 \right]

If there are only two strata (subgroups) then the tests for trend and heterogeneity are identical.

Notes

Both these formulae can be expressed in terms of (oe)(o-e) and vv using β̂i=(oiei)/vi\hat{\beta}_i = (o_i - e_i) / v_i and se(β̂i)2=1/wi=1/vi\mathrm{se}(\hat{\beta}_i)^2 = 1 / w_i = 1 / v_i

First calculate the logrank statistic (oe)(o-e) and its variance vv in each separate stratum (subgroup), and their sums: OE=i=1k(oiei)O - E = \sum_{i=1}^{k} (o_i - e_i) and V=i=1kviV = \sum_{i=1}^{k} v_i

Trend

Define

mi=i=1kivi/Vm_i = \sum_{i = 1}^{k} i v_i/V

and

T=i=1k(imi)(oiei)T = \sum_{i = 1}^{k} (i-m_i)(o_i - e_i)

The variance of TT, var(T)\mathrm{var}(T), is then

var(T)=i=1k(im)2v\mathrm{var}(T) = \sum_{i=1}^{k} (i - m)^2v

and the chi-squared test statistic (1 degree of freedom) for trend is T2var(T)\frac{T^2}{\mathrm{var}(T)}

Heterogeneity

The chi-squared test statistic (k1k - 1 degrees of freedom) for heterogeneity is

i=1k((oiei)2vi)(OE)2V\sum_{i=1}^k \left( \frac{(o_i-e_i)^2}{v_i} \right) - \frac{(O-E)^2}{V}