Title: | Test of Between-Group Differences in the Onset of Senescence |
---|---|
Description: | Implementation of a likelihood ratio test of differential onset of senescence between two groups. Given two groups with measures of age and of an individual trait likely to be subjected to senescence (e.g. body mass), 'OnAge' provides an asymptotic p-value for the null hypothesis that senescence starts at the same age in both groups. The package implements the procedure used in Douhard et al. (2017) <doi:10.1111/oik.04421>. |
Authors: | Laurent Jacob, Frédéric Douhard, Jean-François Lemaître, Jean-Michel Gaillard, Aurélie Siberchicot |
Maintainer: | Aurélie Siberchicot <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-11-19 05:11:25 UTC |
Source: | https://github.com/cran/OnAge |
The function takes as input a log-likelihood function defining a statistical model of the senescence and two datasets. It performs a likelihood ratio test of the null hypothesis that the age at the onset of senescence is the same in the two groups.
onset.test(ll, data1, data2, search.range, CI.lvl=0.95, tol=.Machine$double.eps^0.25, warn=FALSE, do.plot=FALSE, plot.file=NULL, grid.len=100)
onset.test(ll, data1, data2, search.range, CI.lvl=0.95, tol=.Machine$double.eps^0.25, warn=FALSE, do.plot=FALSE, plot.file=NULL, grid.len=100)
ll |
A function computing the log-likelihood of data under a statistical model of the senescence. |
data1 |
A data.frame object containing the data for the first group. |
data2 |
A data.frame object containing the data for the second group. |
search.range |
The range over which the log-likelihood should be maximized with respect to the age at the onset of senescence. |
CI.lvl |
An optional confidence level to obtain a confidence
interval for each onset estimate. No confidence interval is computed
if |
tol |
A tolerance, to be passed to the optimize function. Optional. |
warn |
A logical variable indicating whether the function should issue a warning when the computed likelihood ratio is negative (which may happen for numerical reasons). Optional. |
do.plot |
A logical variable indicating whether the function should
produce a plot of the log-likelihood against age at the onset of senescence (with
vertical dotted lines indicating the confidence interval if |
plot.file |
If not |
grid.len |
Integer value. If |
A list
with elements:
pv |
A p-value for the tested null hypothesis. |
est.1 |
A maximum likelihood estimate for the age at the onset of senescence in the first group. |
est.2 |
A maximum likelihood estimate for the age at the onset of senescence in the second group. |
est.joint |
A maximum likelihood estimate for the age at the onset of senescence in the merged groups. |
CI.1 |
A confidence interval for the age at the onset of
senescence in the first group, with confidence level |
CI.2 |
A confidence interval for the age at the onset of
senescence in the second group, with confidence level |
joint.CI |
A confidence interval for the age at the onset of
senescence in the total group, with confidence level |
lh0 |
The log-likelihood maximized under the null hypothesis. |
lh1 |
The log-likelihood maximized under the alternative hypothesis. |
llr |
The likelihood ratio statistic. |
cvg.ok |
A logical variable indicating whether the computed
likelihood ratio was negative (the returned value is |
if(requireNamespace("lme4", quietly=TRUE)) { data(RoeDeerMassData) RoeDeerMassData$ID <- factor(RoeDeerMassData$ID) RoeDeerMassData$cohort <- factor(RoeDeerMassData$cohort) dataFCH <- RoeDeerMassData[RoeDeerMassData$sex%in%"F"& RoeDeerMassData$population%in%"CH", ] dataMCH <- RoeDeerMassData[RoeDeerMassData$sex%in%"M"& RoeDeerMassData$population%in%"CH", ] dataFTF <- RoeDeerMassData[RoeDeerMassData$sex%in%"F"& RoeDeerMassData$population%in%"TF", ] dataMTF <- RoeDeerMassData[RoeDeerMassData$sex%in%"M"& RoeDeerMassData$population%in%"TF", ] ## b1: function for piecewise regression (transforms x into 0 before bp) b1 <- function(x, bp) ifelse(x < bp, 0, x - bp) ## Use this function to define the model in which the differential ## onset hypothesis is tested. ll <- function(thr, dataIn){ logLik(lme4::lmer(body.mass ~ b1(age, thr) + age.at.last.capture + last.year.of.capture + (1|ID) + (1|cohort), data=dataIn, REML="FALSE")) } search.range <- c(6,12) # data not available before 6 years old search.range.TF <- search.range.CH <- search.range ## Not run: # if you don't run the example in RStudio, create a new graphic # window with suitable dimensions if(.Platform$GUI!="RStudio") {dev.new(width=15, height=5)} # all graphs are square par(pty="s") # test for Trois Fontaines res.tf <- onset.test(ll, dataFTF, dataMTF, search.range.TF, do.plot=TRUE) if(.Platform$GUI!="RStudio") {dev.new(width=15, height=5)} par(pty="s") # test for Chizé res.ch <- onset.test(ll, dataFCH, dataMCH, search.range.CH, do.plot=TRUE) cat(sprintf("p-value for differential age at onset is %g in Trois Fontaines, %g in Chizé", res.tf$pv, res.ch$pv)) ## End(Not run) # a shorter executable example for Trois Fontaines set.seed(40) shortdataFTF <- dataFTF[sample(1:NROW(dataFTF), 200), ] shortdataMTF <- dataMTF[sample(1:NROW(dataMTF), 100), ] res.tf.short <- onset.test(ll, shortdataFTF, shortdataMTF, search.range.TF, do.plot=FALSE, CI.lvl=NA) }
if(requireNamespace("lme4", quietly=TRUE)) { data(RoeDeerMassData) RoeDeerMassData$ID <- factor(RoeDeerMassData$ID) RoeDeerMassData$cohort <- factor(RoeDeerMassData$cohort) dataFCH <- RoeDeerMassData[RoeDeerMassData$sex%in%"F"& RoeDeerMassData$population%in%"CH", ] dataMCH <- RoeDeerMassData[RoeDeerMassData$sex%in%"M"& RoeDeerMassData$population%in%"CH", ] dataFTF <- RoeDeerMassData[RoeDeerMassData$sex%in%"F"& RoeDeerMassData$population%in%"TF", ] dataMTF <- RoeDeerMassData[RoeDeerMassData$sex%in%"M"& RoeDeerMassData$population%in%"TF", ] ## b1: function for piecewise regression (transforms x into 0 before bp) b1 <- function(x, bp) ifelse(x < bp, 0, x - bp) ## Use this function to define the model in which the differential ## onset hypothesis is tested. ll <- function(thr, dataIn){ logLik(lme4::lmer(body.mass ~ b1(age, thr) + age.at.last.capture + last.year.of.capture + (1|ID) + (1|cohort), data=dataIn, REML="FALSE")) } search.range <- c(6,12) # data not available before 6 years old search.range.TF <- search.range.CH <- search.range ## Not run: # if you don't run the example in RStudio, create a new graphic # window with suitable dimensions if(.Platform$GUI!="RStudio") {dev.new(width=15, height=5)} # all graphs are square par(pty="s") # test for Trois Fontaines res.tf <- onset.test(ll, dataFTF, dataMTF, search.range.TF, do.plot=TRUE) if(.Platform$GUI!="RStudio") {dev.new(width=15, height=5)} par(pty="s") # test for Chizé res.ch <- onset.test(ll, dataFCH, dataMCH, search.range.CH, do.plot=TRUE) cat(sprintf("p-value for differential age at onset is %g in Trois Fontaines, %g in Chizé", res.tf$pv, res.ch$pv)) ## End(Not run) # a shorter executable example for Trois Fontaines set.seed(40) shortdataFTF <- dataFTF[sample(1:NROW(dataFTF), 200), ] shortdataMTF <- dataMTF[sample(1:NROW(dataMTF), 100), ] res.tf.short <- onset.test(ll, shortdataFTF, shortdataMTF, search.range.TF, do.plot=FALSE, CI.lvl=NA) }
A dataset containing the age, body weight and other attributes of 454 roe deer from Chizé and Trois Fontaines.
data(RoeDeerMassData)
data(RoeDeerMassData)
A data frame with 1428 rows and 16 variables:
An individual specific identifier.
The age of the individual (in years).
The sex of the individual (F for females, M for males).
The population site of the individual: either Chizé (CH) or Trois Fontaines (TF).
The year of birth of the individual.
The individual body mass measurement at this particular age (in kg).
The year of capture of the individual for this particular body mass measurement.
The age of the individual at its last capture (in years).
A binary variable indicating whether or not the body mass measurement was done in the last capture of individual's life (no = 0; yes = 1).
The predicted body mass during the first winter at the median date of capture (27th of January) (in kg).
The difference between the individual early mass and the average early mass of individuals within each sex and population (in kg).
Median body mass during the prime age stage between four (after body growth has ceased) and six years of age (when senescence in body mass can begin)
The body mass gain corresponding to the difference between adult body mass and early mass (in kg).
The body mass gain once the effect of early mass has been accounted for within each sex and population (i.e. residual of the linear regression model between early mas and mass gain) (in kg)
The binary variable indicating whether the individual has an early mass less, or equal or greater than the median early mass within each sex and population (no = 0; yes =1).
The binary variable indicating whether the individual has a late growth less, or equal or greater than the median early mass within each sex and population (no = 0; yes = 1).
http://onlinelibrary.wiley.com/doi/10.1111/oik.04421/abstract
data(RoeDeerMassData) str(RoeDeerMassData)
data(RoeDeerMassData) str(RoeDeerMassData)