Skip to contents

The residual score indicates to what extent a person's phenotype risk score for a given disease deviates from the expected score, after adjusting for the person's characteristics in a linear model.


getResidualScores(demos, scores, lmFormula)



A data.table of characteristics for each person in the cohort. Must have column person_id.


A data.table containing the phenotype risk score for each person for each disease. Must have columns person_id, disease_id, and score.


A formula representing the linear model to use for calculating residual scores. All terms in the formula must correspond to columns in demos.


A data.table, based on scores, with an additional column resid_score. Residual scores for each disease are standardized to have unit variance.



# map ICD codes to phecodes
phecodeOccurrences = getPhecodeOccurrences(icdSample)

# calculate weights (using the prevalence method)
weights = getWeights(demoSample, phecodeOccurrences)

# OMIM disease IDs for which to calculate phenotype risk scores
diseaseId = 154700

# map diseases to phecodes
diseasePhecodeMap = mapDiseaseToPhecode()

# calculate scores
scores = getScores(
  demoSample, phecodeOccurrences, weights, diseasePhecodeMap[disease_id == diseaseId])

# calculate residual scores
rscores = getResidualScores(demoSample, scores, lmFormula = ~ sex)