singcar

singcar: Comparing single cases to small samples in R - Published in JOSS (2021)

https://github.com/jorittmo/singcar

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 15 DOI reference(s) in README and JOSS metadata
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Scientific Fields

Physics Physical Sciences - 40% confidence
Last synced: 4 months ago · JSON representation

Repository

singcar: A package for statistically comparing single cases to normative controls

Basic Info
  • Host: GitHub
  • Owner: jorittmo
  • License: other
  • Language: R
  • Default Branch: master
  • Homepage:
  • Size: 541 KB
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • Open Issues: 1
  • Releases: 4
Created over 5 years ago · Last pushed almost 3 years ago
Metadata Files
Readme Changelog Contributing License Code of conduct

README.md

singcar

CRAN CRAN downloads total CRAN downloads month Travis build status License: MIT <!-- badges: end -->

The aim of the R package singcar is to provide and encourage usage of appropriate statistical methods for comparing a case against a control sample. For instance, they may commonly be done in a neuropsychological context, in which an individual has incurred a specific brain injury and we wish to test whether this damage has led to an impairment of some cognitive function and whether two different functions are dissociable. For many functions there is normed data available which the patient can be compared against directly. However, when this is not possible a control sample estimating the population, against which we wish to compare the patient, must be used. Both frequentist and Bayesian methods have been developed to do this, first and foremost by John Crawford and Paul Garthwaite (Crawford et al., 2011; Crawford & Garthwaite, 2002, 2007, 2005; Crawford & Howell, 1998). It is these methods that singcar implements. Power calculators for these tests are also provided. Although the canonical applications for these tests are in Cognitive Neuropsychology or Clinical Neuropsychology, they are potentially applicable to any circumstance in which a measure taken from a single individual is to be compared against data from a normative sample (i.e. a control group). It should be noted that these statistical methods could also be applied as a general method of outlier detection in small samples.

To cite this package you can use:

  • Rittmo, J, Ö., McIntosh, R, D. (2021). singcar: Comparing single cases to small samples in R. Journal of Open Source Software, 6(68), 3887, https://doi.org/10.21105/joss.03887

Installation

singcar is now available on CRAN! To get this stable version run:

R install.packages("singcar") library("singcar")

You can install the unstable(!) developmental version of singcar by running the following:

R install.packages("devtools") library("devtools") install_github("jorittmo/singcar") library("singcar")

Issues

Please report any bugs, issues or feature requests in the issue tracker.

Contributions

Contributions are highly appreciated and contribution guidelines prior to submitting a pull request.

Example

The package comes with the dataset size_weight_illusion, a neuropsychological dataset from an investigation of the size-weight illusion in DF, a patient with visual form agnosia following following bilateral lesions to the lateral occipital complex (Hassan et al., 2020). It was investigated whether DF experienced visual size-weight illusion to the same extent as controls (n = 28) and whether visual and kinaesthetic size-weight illusion could be dissociable. Below follows examples of how to analyse this dataset using the tests provided in singcar.

Testing for a deficit

If we want to assess whether DF has an impairment compared to controls on visual size-weight illusion we can test this using a modified two-sample t-test, called TD (test of deficit: Crawford & Howell, 1998).

``` r library(singcar)

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

TD(case = DFVSWI, controls = CONVSWI, conf_int = TRUE)

Crawford-Howell (1998) t-test

data: case = 0.03 and controls (M = 0.16, SD = 0.08, N = 28)

t = -1.7243, df = 27, p-value = 0.04804

alternative hypothesis: true difference between case and controls is less than 0

sample estimates:

Standardised case score (Z-CC), 95% CI [-2.34, -1.15] Proportion below case (%), 95% CI [0.95, 12.47]

-1.754857 4.804003

``` This can similarly be tested with a Bayesian version of the same test, yielding approximately (since this test is based on MCMC methods) the same output (Crawford & Garthwaite, 2007).

``` r

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

BTD(case = DFVSWI, controls = CONVSWI)

Bayesian Test of deficit by Crawford and Garthwaite (2007)

data: case = 0.03 and controls (M = 0.16, SD = 0.08, N = 28)

est. z = -1.7388, df = 27, p-value = 0.04803

alternative hypothesis: true difference between case and controls is less than 0

sample estimates:

Std. case score (Z-CC), 95% credible interval [-2.34, -1.15] Proportion below case (%), 95% credible interval [0.96, 12.44]

-1.754857 4.802900

``` If the control sample for a study is not appropriately matched to the case on variables such as e.g. age or education level it is appropriate to use tests that account for this by allowing for the inclusion of covariates. Including theoretically sound covariates is often a good idea. To do this Crawford et al. (2011) extended their Bayesian verison of the TD. This test assess the patient on the task of interest by essentially comparing him/her to the controls with the same score on the covariate.

``` r

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

Extracting the coviariate below

DFage <- sizeweightillusion[sizeweightillusion$PPT == "DF", "YRS"] # Patient CONage <- sizeweightillusion[sizeweightillusion$PPT != "DF", "YRS"] # Controls

BTDcov(casetask = DFVSWI, casecovar = DFage, controltask = CONVSWI, controlcovar = CON_age)

Bayesian Test of deficit with Covariates

data: case = 0.03 and controls (M = 0.16, SD = 0.08, N = 28)

est. z = -1.6828, p-value = 0.05386

alternative hypothesis: true difference between case and controls is less than 0

sample estimates:

Std. case difference (Z-CCC), 95% credible interval [-2.31, -1.10] Proportion below case (%), 95% credible interval [1.05, 13.52]

-1.749556 5.386088

```

Testing for a dissociation

If we want to assess whether DF has a dissociation between two functions we can use a modified paired samples t-test to assess the size of the difference between the case scores from the two tasks to the distribution of differences between the tasks in the controls. This can however only be done directly using the t-distribution if the tasks are measured on the same scale and is called the unstandardised difference test (UDT: Crawford & Garthwaite, 2005). In the size_weight_illusion dataset it is possible to use this test to whether patient DF exhibits a dissociation between visual size-weight illusion and kinaesthetic size-weight illusion because the visual and kinaesthetic conditions are parallel versions of the same task, with different sensory cues. This would be done as shown below:

``` r library(singcar)

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

Extracting scores from the kinaesthetic size-weight illusion from sizeweightillusion

DFKSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "KSWI"] # Patient CONKSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "KSWI"] # Controls

UDT(casea = DFVSWI, caseb = DFKSWI, controlsa = CONVSWI, controlsb = CONKSWI)

Unstandardised Difference Test

data: Case score A: 0.03, Case score B: 0.10, Controls A (mean, sd): (0.16, 0.08), Controls B (mean, sd): (0.18, 0.10)

t = -0.6667, df = 27, p-value = 0.5106

alternative hypothesis: true difference between tasks is not equal to 0

sample estimates:

Standardised case score, task A (Z-CC) Standardised case score, task B (Z-CC)

-0.13647439 -0.07931545

Standardised task discrepancy (Z-DCC), 95% CI [-1.53, -0.59] Proportion below case (%), 95% CI [6.35, 27.68]

-1.06478887 25.53097678

```

Most often this is not possible because we wish to estimate abnormality of discrepancy on tasks that are not comparable. So otherwise, that is if the scores must be standardised to be comparable, a statistic that approximates the t-distribution has been developed and should be used (the revised standardised difference test RSDT: Crawford & Garthwaite, 2005). The visual and kinaesthetic size-weight illusion will be used for illustrative purposes here as well:

``` r

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

Extracting scores from the kinaesthetic size-weight illusion from sizeweightillusion

DFKSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "KSWI"] # Patient CONKSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "KSWI"] # Controls

RSDT(casea = DFVSWI, caseb = DFKSWI, controlsa = CONVSWI, controlsb = CONKSWI)

Revised Standardised Difference Test

data: Case score A: 0.03, Case score B: 0.10, Controls A (mean, sd): (0.16, 0.08), Controls B (mean, sd): (0.18, 0.10)

approx. abs. t = 1.015, df = 27, p-value = 0.3191

alternative hypothesis: true difference between tasks is not equal to 0

sample estimates:

Case score on task A as standard (z) score Case score on task B as standard (z) score

-1.7548574 -0.7836956

Std. effect size (Z-DCC) for task diff. between case and controls Proportion of control population with more extreme task difference

-1.0647889 15.9560625

`` A Bayesian version of this test was also developed (Crawford & Garthwaite, 2005), however, unlikeTDandBTDtheRSDTandBSDT(Bayesian standardised difference test) differ somewhat andBSDThas been shown to keep a better control of Type I errors if a patient exhibits extreme deficits on both tasks of interest. Therefore theBSDTis recommended aboveRSDT. The usage of the two R functions is very similar. Since theBSDT` is based on MCMC methods it can be quite computationally intensive, depending on the number of iterations you choose.

``` r

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

Extracting scores from the kinaesthetic size-weight illusion from sizeweightillusion

DFKSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "KSWI"] # Patient CONKSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "KSWI"] # Controls

BSDT(casea = DFVSWI, caseb = DFKSWI, controlsa = CONVSWI, controlsb = CONKSWI, iter = 10^6)

Bayesian Standardised Difference Test

data: Case score A: 0.03, Case score B: 0.10, Controls A (mean, sd): (0.16, 0.08), Controls B (mean, sd): (0.18, 0.10)

est. z = -1.0736, p-value = 0.3067

alternative hypothesis: true difference between tasks is not equal to 0

sample estimates:

Case score on task A as standard (z) score

-1.7548574

Case score on task B as standard (z) score

-0.7836956

Std. effect size (Z-DCC) for task diff. between case and controls, 95% credible interval [-1.71, -0.45]

-1.0647889

Proportion of control population with more extreme task difference, 95% credible interval [4.32, 32.47]

15.3357743

```

Just as for BTD a version of BSDT allowing for covariates has been developed. This test assess the patient on the discrepancy between the tasks of interest by essentially comparing him/her to the controls with the same score on the covariate.

``` r

Extracting scores from the visual size-weight illusion from sizeweightillusion

DFVSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "VSWI"] # Patient CONVSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "VSWI"] # Controls

DFKSWI <- sizeweightillusion[sizeweightillusion$PPT == "DF", "KSWI"] # Patient CONKSWI <- sizeweightillusion[sizeweightillusion$PPT != "DF", "KSWI"] # Controls

Extracting the coviariate below

DFage <- sizeweightillusion[sizeweightillusion$PPT == "DF", "YRS"] # Patient CONage <- sizeweightillusion[sizeweightillusion$PPT != "DF", "YRS"] # Controls

BSDTcov(casetasks = c(DFVSWI, DFKSWI ), casecovar = DFage, controltasks = cbind(CONVSWI, CONKSWI), controlcovar = CON_age, iter = 10^5)

Bayesian Standardised Difference Test with Covariates

data: Case score Y1: 0.03, Case score Y2: 0.10, Controls score Y1: 0.16, Controls score Y2: 0.18

ave. z = -1.0229, p-value = 0.3303

alternative hypothesis: true difference between tasks is not equal to 0

sample estimates:

Case score on task X as standard (z) score

-1.754857

Case score on task Y as standard (z) score

-0.783696

Std. effect size (Z-DCCC) for task diff. between case and controls, 95% credible interval [-1.67, -0.40]

-1.064152

Proportion of control population with more extreme task difference, 95% credible interval [4.77, 34.54]

16.510000

``` All of the functions above can also take summary (mean, sd, control sample size) data as input.

Power calculators

A further capacity of singcar is that it can be used to calculate power for for these single case-control comparisons. Calculations for all Bayesian tests and RSDT are simulation based and (especially the tests with covariates) can be computationally intense. Calculators for TD and UDT (unstandardised difference test) are exact (their power functions have been derived analytically) and can both be used to find a specific sample size given a desired power. For the other calculators all parameters must be given. Means and standard deviations for the control population are at default set to 0 and 1 meaning that the case value will be interpreted as differences from the mean in standard deviations, these parameter values can be changed as you like. Examples are given below:

``` r TD_power(case = -2, power = 0.8, mean = 0, sd = 1, alternative = "two.sided")

[1] "Power(0.44280) will not increase more than 0.5% for any additional participant over n = 16"

n power

1 16 0.4428042

TDpower(case = 70, samplesize = 10, mean = 100, sd = 15, alternative = "less", alpha = 0.1)

[1] 0.7039033

RSDTpower(casea = 70, caseb = 20, meana = 100, meanb = 25, sda = 15, sdb = 10, samplesize = 10)

[1] 0.5689

Takes long time to compute

BTDcovpower(case = -2, casecov = 0, controltask = c(0, 1), controlcovar = c(0, 1), cormat = diag(2), sample_size = 10)

[1] 0.511

```

References

Crawford, J., & Garthwaite, P. (2002). Investigation of the single case in neuropsychology: Confidence limits on the abnormality of test scores and test score differences. Neuropsychologia, 40(8), 1196-1208. https://doi.org/10.1016/S0028-3932(01)00224-X

Crawford, J., & Garthwaite, P. (2007). Comparison of a single case to a control or normative sample in neuropsychology: Development of a Bayesian approach. Cognitive Neuropsychology, 24(4), 343-372. https://doi.org/10.1080/02643290701290146

Crawford, J., & Garthwaite, P. (2005). Testing for Suspected Impairments and Dissociations in Single-Case Studies in Neuropsychology: Evaluation of Alternatives Using Monte Carlo Simulations and Revised Tests for Dissociations. Neuropsychology, 19(3), 318-331. https://doi.org/10.1037/0894-4105.19.3.318

Crawford, J., Garthwaite, P., & Ryan, K. (2011). Comparing a single case to a control sample: Testing for neuropsychological deficits and dissociations in the presence of covariates. Cortex, 47(10), 1166-1178. https://doi.org/10.1016/j.cortex.2011.02.017

Crawford, J., & Howell, D. (1998). Comparing an Individual's Test Score Against Norms Derived from Small Samples. The Clinical Neuropsychologist, 12(4), 482-486. https://doi.org/10.1076/clin.12.4.482.7241

Hassan, E. K., Sedda, A., Buckingham, G., & McIntosh, R. D. (2020). The size-weight illusion in visual form agnosic patient DF. Neurocase, 1-8. https://doi.org/10.1080/13554794.2020.1800748

Owner

  • Name: Jonathan Rittmo
  • Login: jorittmo
  • Kind: user

Data provider, data admirer

JOSS Publication

singcar: Comparing single cases to small samples in R
Published
December 30, 2021
Volume 6, Issue 68, Page 3887
Authors
Jonathan Ö. Rittmo ORCID
Human Cognitive Neuroscience, Psychology, University of Edinburgh, UK
Robert D. McIntosh ORCID
Human Cognitive Neuroscience, Psychology, University of Edinburgh, UK
Editor
Charlotte Soneson ORCID
Tags
Case control comparison Neuropsychology Brain lesion studies Small samples

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 129
  • Total Committers: 1
  • Avg Commits per committer: 129.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jonathan Rittmo j****o@g****m 129

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 4
  • Total pull requests: 0
  • Average time to close issues: 3 months
  • Average time to close pull requests: N/A
  • Total issue authors: 3
  • Total pull request authors: 0
  • Average comments per issue: 3.25
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jorittmo (2)
  • ethanknights (1)
  • craddm (1)
Pull Request Authors
Top Labels
Issue Labels
bug (1) enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 276 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 5
  • Total maintainers: 1
cran.r-project.org: singcar

Comparing Single Cases to Small Samples

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 276 Last month
Rankings
Forks count: 17.8%
Stargazers count: 28.5%
Dependent packages count: 29.8%
Average: 31.2%
Dependent repos count: 35.5%
Downloads: 44.7%
Maintainers (1)
Last synced: 4 months ago

Dependencies

DESCRIPTION cran
  • R >= 2.10 depends
  • CholWishart * imports
  • MASS * imports
  • stats * imports
  • withr * imports
  • bookdown * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 2.1.0 suggests