# Two-Stage Summary Statistics approach: flip2sss

# Info data

Original data are in Kaggle https://www.kaggle.com/datasets/jboysen/mri-and-alzheimers

Context:

The Open Access Series of Imaging Studies (OASIS) is a project aimed at making MRI data sets of the brain freely available to the scientific community. By compiling and freely distributing MRI data sets, we hope to facilitate future discoveries in basic and clinical neuroscience. OASIS is made available by the Washington University Alzheimer’s Disease Research Center, Dr. Randy Buckner at the Howard Hughes Medical Institute (HHMI)( at Harvard University, the Neuroinformatics Research Group (NRG) at Washington University School of Medicine, and the Biomedical Informatics Research Network (BIRN).

Content:

Longitudinal MRI Data in Nondemented and Demented Older Adults: This set consists of a longitudinal collection of 150 subjects aged 60 to 96. Each subject was scanned on two or more visits, separated by at least one year for a total of 373 imaging sessions. For each subject, 3 or 4 individual T1-weighted MRI scans obtained in single scan sessions are included. The subjects are all right-handed and include both men and women. 72 of the subjects were characterized as nondemented throughout the study. 64 of the included subjects were characterized as demented at the time of their initial visits and remained so for subsequent scans, including 51 individuals with mild to moderate Alzheimer’s disease. Another 14 subjects were characterized as nondemented at the time of their initial visit and were subsequently characterized as demented at a later visit.

Acknowledgements:

When publishing findings that benefit from OASIS data, please include the following grant numbers in the acknowledgements section and in the associated Pubmed Central submission: P50 AG05681, P01 AG03991, R01 AG021910, P20 MH071616, U24 RR0213

# Import data

    data("oasis",package="jointest")

    # from here on 0 means Age=77 (which is about the mean)
    oasis$Age=oasis$Age-77

    library(ggplot2)
    p <- ggplot(oasis,aes(Group,nWBV,color=Group))
    p+geom_point(size = 3) +geom_boxplot(alpha=.1) + theme_bw()

    p <- ggplot(oasis,aes(Age,nWBV,color=Group))
    p+geom_point(size = 3) +geom_smooth(method = lm) + theme_bw()
    #> `geom_smooth()` using formula = 'y ~ x'

    p=ggplot(oasis, aes(x = Age, y = nWBV, colour = Group, group = Subject.ID)) + geom_line(aes(linetype=Gender)) + geom_point()
    p + theme_bw()

# Mixed Model Approach

    library(lme4)
    #> Caricamento del pacchetto richiesto: Matrix
    #> Warning: il pacchetto 'Matrix' è stato creato con R versione 4.4.2
    library(ggplot2)

    mod=lmer(nWBV ~ Age*Group+Gender*Group+ (1+Age|Subject.ID),data=oasis)
    summary(mod)
    #> Linear mixed model fit by REML ['lmerMod']
    #> Formula: nWBV ~ Age * Group + Gender * Group + (1 + Age | Subject.ID)
    #>    Data: oasis
    #>
    #> REML criterion at convergence: -1933.9
    #>
    #> Scaled residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.0874 -0.4323  0.0200  0.4135  3.7384
    #>
    #> Random effects:
    #>  Groups     Name        Variance  Std.Dev.  Corr
    #>  Subject.ID (Intercept) 8.191e-04 0.0286202
    #>             Age         7.901e-07 0.0008889 0.23
    #>  Residual               6.224e-05 0.0078892
    #> Number of obs: 373, groups:  Subject.ID, 150
    #>
    #> Fixed effects:
    #>                          Estimate Std. Error t value
    #> (Intercept)             0.7452316  0.0042193 176.623
    #> Age                    -0.0032509  0.0002945 -11.040
    #> GroupConverted         -0.0032100  0.0103316  -0.311
    #> GroupDemented          -0.0240630  0.0069930  -3.441
    #> GenderM                -0.0168072  0.0075529  -2.225
    #> Age:GroupConverted     -0.0017799  0.0007001  -2.542
    #> Age:GroupDemented      -0.0004456  0.0004969  -0.897
    #> GroupConverted:GenderM  0.0026959  0.0194691   0.138
    #> GroupDemented:GenderM   0.0045382  0.0106025   0.428
    #>
    #> Correlation of Fixed Effects:
    #>             (Intr) Age    GrpCnv GrpDmn GendrM Ag:GrC Ag:GrD GrC:GM
    #> Age          0.073
    #> GroupCnvrtd -0.408 -0.030
    #> GroupDemntd -0.603 -0.044  0.246
    #> GenderM     -0.554  0.017  0.226  0.334
    #> Ag:GrpCnvrt -0.031 -0.421  0.053  0.019 -0.007
    #> Ag:GrpDmntd -0.043 -0.593  0.018  0.056 -0.010  0.249
    #> GrpCnvrt:GM  0.215 -0.007 -0.535 -0.130 -0.388 -0.116  0.004
    #> GrpDmntd:GM  0.395 -0.012 -0.161 -0.655 -0.712  0.005  0.057  0.276
    anova(mod)
    #> Analysis of Variance Table
    #>              npar    Sum Sq   Mean Sq  F value
    #> Age             1 0.0161367 0.0161367 259.2690
    #> Group           2 0.0016226 0.0008113  13.0349
    #> Gender          1 0.0005399 0.0005399   8.6740
    #> Age:Group       2 0.0004136 0.0002068   3.3227
    #> Group:Gender    2 0.0000114 0.0000057   0.0918

REMARK: Note that without the centering `oasis$Age=oasis$Age-77`: Model failed to converge with max|grad| = 0.640671 (tol = 0.002, component 1)

# Two-Stage Summary Statistics approach: flip2sss (= Second-level, Group-level Analisys)

    library(jointest)
    #>
    #> Caricamento pacchetto: 'jointest'
    #> Il seguente oggetto è mascherato _per_ '.GlobalEnv':
    #>
    #>     oasis
    #> Il seguente oggetto è mascherato da 'package:stats':
    #>
    #>     p.adjust

    mod=flip2sss(nWBV ~ Age*Group+Gender*Group,
                 cluster =oasis$Subject.ID,data=oasis)
    summary(mod)
    #>         Model                  Coeff     Estimate       Score Std. Error
    #> 1 .Intercept.            (Intercept)  0.746877560 96.34720521 5.05960944
    #> 2 .Intercept.         GroupConverted  0.019579080  0.39618845 0.24331389
    #> 3 .Intercept.          GroupDemented -0.043952038 -1.79994059 0.35742608
    #> 4 .Intercept.                GenderM -0.025517820 -1.05684064 0.35118475
    #> 5 .Intercept. GroupConverted:GenderM -0.003714505 -0.02602376 0.14265802
    #> 6 .Intercept.  GroupDemented:GenderM  0.022234130  0.42399217 0.23638372
    #> 7         Age                    Age -0.003572179 -0.67871410 0.08965151
    #> 8         Age     GroupConverted:Age -0.002644949 -0.08191186 0.03355236
    #> 9         Age      GroupDemented:Age -0.003083741 -0.25459218 0.05592513
    #>      z value    Part. Cor      p
    #> 1 19.0424194  0.992654732 0.0002
    #> 2  1.6283018  0.084881099 0.0216
    #> 3 -5.0358402 -0.262511315 0.0002
    #> 4 -3.0093580 -0.156873631 0.0004
    #> 5 -0.1824206 -0.009509332 0.7644
    #> 6  1.7936606  0.093501023 0.1106
    #> 7 -7.5705822 -0.393045045 0.0002
    #> 8 -2.4413146 -0.126746737 0.0040
    #> 9 -4.5523750 -0.236347533 0.0002

    #ANOVA-like combination
    #Overall
    summary(combine(mod))
    #>     Model Coeff Stat nTests        S     p
    #> 1 Overall  many maxT      9 96.34721 2e-04
    #by Variables
    summary(combine_contrasts(mod))
    #>         Model         Coeff        Stat nTests          S      p
    #> 1 .Intercept.   (Intercept) Mahalanobis      1  0.1601818 0.0002
    #> 2 .Intercept.         Group Mahalanobis      2 22.1921647 0.0002
    #> 3 .Intercept.       GenderM Mahalanobis      1  0.0473890 0.0004
    #> 4 .Intercept. Group:GenderM Mahalanobis      2  3.3659750 0.1892
    #> 5         Age           Age Mahalanobis      1  0.1258807 0.0002
    #> 6         Age     Group:Age Mahalanobis      2 22.5820162 0.0002

    # p <- ggplot(oasis1lev,aes(Group,Interc,color=Group))
    # p+geom_point(size = 3) +geom_boxplot(alpha=.1) + theme_bw()
    #
    #
    # p <- ggplot(oasis1lev,aes(Group,Slope,color=Group))
    # p+geom_point(size = 3) +geom_boxplot(alpha=.1) + theme_bw()
    #