Statistical tests for paired continuous variable.

paired_test_continuous(group, x)

Arguments

group

(fct) vector of groups

x

(num) vector of observations. Note: length of `x` is considered equal to the number of subjects by the number of groups. Observation must be provided by subject (e.g. c(a1, b1, c1, a2, b2, c2, a3, b3, c3, a4, b4, c4), where the letters, a, b, c, and d represents the groups and the numbers represents the patients' ids). Note only patient with observation in all the levels considered will be used.

Value

A list with components `P` (the computed P-value), `stat` (the test statistic, either t or F), `df` (degrees of freedom), `testname` (test name), `statname` (statistic name), `namefun` ("paired_tstat", "rep_aov"), `latexstat` (LaTeX representation of statname), `plotmathstat` (for R - the plotmath representation of `statname`, as a character string), `note` (contains a character string note about the test).

Details

If the test is requested for two paired groups, the t.test is used.

If the test is requested for more than two groups, the test based on ANOVA for repeated measures is used (powered by aov)

Note

This function could be used as `conTest` option in the summary.formula with method `reverse`.

Examples

# \donttest{
  library(Hmisc)

  ## two groups
  summary(Species ~ .,
    data = iris[iris[["Species"]] != "setosa", ],
    method = "reverse",
    test = TRUE,
    conTest = paired_test_continuous
  )
#> 
#> 
#> Descriptive Statistics by Species
#> 
#> +------------+---------------------+---------------------+------------------------+
#> |            |versicolor           |virginica            |  Test                  |
#> |            |(N=50)               |(N=50)               |Statistic               |
#> +------------+---------------------+---------------------+------------------------+
#> |Sepal.Length|    5.600/5.900/6.300|    6.225/6.500/6.900| t=-5.28 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+
#> |Sepal.Width |    2.525/2.800/3.000|    2.800/3.000/3.175| t=-3.08 d.f.=49 P=0.003|
#> +------------+---------------------+---------------------+------------------------+
#> |Petal.Length|    4.000/4.350/4.600|    5.100/5.550/5.875|t=-12.09 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+
#> |Petal.Width |       1.2/1.3/1.5   |       1.8/2.0/2.3   |t=-14.69 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+

  ## more than two groups
  summary(Species ~ .,
    data = iris,
    method = "reverse",
    test = TRUE,
    conTest = paired_test_continuous
  )
#> 
#> 
#> Descriptive Statistics by Species
#> 
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |            |setosa              |versicolor          |virginica           |  Test                 |
#> |            |(N=50)              |(N=50)              |(N=50)              |Statistic              |
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Sepal.Length|   4.800/5.000/5.200|   5.600/5.900/6.300|   6.225/6.500/6.900| F=30.55 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Sepal.Width |   3.200/3.400/3.675|   2.525/2.800/3.000|   2.800/3.000/3.175| F=12.63 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Petal.Length|   1.400/1.500/1.575|   4.000/4.350/4.600|   5.100/5.550/5.875|F=322.89 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Petal.Width |      0.2/0.2/0.3   |      1.2/1.3/1.5   |      1.8/2.0/2.3   |F=234.21 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+

  ## without Hmisc
  two_obs <- iris[["Sepal.Length"]][iris[["Species"]] != "setosa"]
  two_groups <- iris[["Species"]][iris[["Species"]] != "setosa"]
  paired_test_continuous(two_groups, two_obs)
#> Warning: Removed 98 rows containing missing values.
#> Warning: Only one group with data, no paired test is done
#> $P
#> P 
#> 1 
#> 
#> $stat
#> XXX 
#> Inf 
#> 
#> $df
#> df 
#>  0 
#> 
#> $testname
#> [1] "notestname"
#> 
#> $statname
#> [1] "nostatname"
#> 
#> $namefun
#> [1] "nonamefun"
#> 
#> $note
#> [1] "Only one group with data, no paired test is done."
#> 

  obs <- iris[["Sepal.Length"]]
  many_groups <- iris[["Species"]]
  paired_test_continuous(many_groups, obs)
#> $P
#>           P 
#> 8.72911e-12 
#> 
#> $stat
#>        F 
#> 30.54869 
#> 
#> $df
#> df 
#>  2 
#> 
#> $testname
#> [1] "Repeated-measure AOV"
#> 
#> $statname
#> [1] "F"
#> 
#> $namefun
#> [1] "rep_aov"
#> 
#> $latexstat
#> [1] "F_{df}"
#> 
#> $plotmathstat
#> [1] "F[df]"
#> 
#> $note
#> [1] "More than two groups: ANOVA for repeated measure is used."
#> 
# }