-
Notifications
You must be signed in to change notification settings - Fork 0
checkOnsetVariability
Updated 14/10/2022
The repository is maintained by Thomas Spargo (thomas.spargo@kcl.ac.uk) - please reach out with any questions.
The checkOnsetVariability function can be used to give an indication about whether penetrance estimates might be affected substantially by age of sampling, when the difference in variability between groups is large.
#Create dummy data (with very unequal onset distribution):
df<- data.frame(groups = factor(c(rep("A",100),rep("B",100))), ageonset = c(rnorm(n=100,mean=50,sd=10),rnorm(n=100,mean=50,sd=5)))
#Apply function with default settings, passed to dataframe argument:
checkOnsetVariability(dataset = df)
#Apply default settings, passing vectors separately to groups and ageonset, and supplying a title for the plot:
checkOnsetVariability(groups = df$groups,ageonset=df$ageonset, main="Example Variability plot")
#Apply function, generating cumulative density plot, centred on the 'median' for each group:
checkOnsetVariability(dataset = df, centre_on="median",plotType="cumulative")
dataset - (optional) A dataframe that must contain columns named "groups" and "ageonset" (additional columns will be ignored). See groups and ageonset arguments for further details.
groups - (optional) factor or character vector flagging to which group the corresponding ageonset value belongs. Factor class is recommended so that group order can be retained. Not specified if dataset argument supplied.
ageonset - (optional) numeric vector indicating the age at which disease onsets, becoming penetrant, for each person. Not specified if dataset argument supplied.
center_on - must be either a character string of "mean" or "median", or a numeric between 0 and 1. These determine how age of onset values will be centered for each group. Numeric values are parsed by the quantile() function. Defaults to "mean"
plotType - character string of either "density" or "cumulative". indicates whether to plot density curve or cumulative density function for each group. Defaults to "density"
... - arguments passed to plot(); cannot currently accept any of: x, y, col, ylim, xlim, xlab, type, xlab, ylab, sub since these are defined explicitly within the main function.
The input data should be passed either as a dataframe to the dataset argument, from which groups and ageonset vectors will be extracted, or as separate vectors to groups and ageonset respectively.
The groups vector is recommended in order to retain factor order in the resulting plots.
This function returns a base R plot comparing variability in onset between two groups. Visual inspection of this plot can give an indication of how similar variability in age of onset is between the groups compared.
The plot 'sub' message indicates the relative difference in span of time between the first and third quartiles of onset between groups. Values:
- ≈1 represent a that the variability in age of onset is similar between groups.
- <1 indicate that the group plotted in blue has a longer interquartile interval.
- >1 indicate that the group plotted in red has a a longer interquartile interval.
A longer-form version of the variability in age of onset message is printed to the console, giving slightly more explicit detail about how the number relates to the two supplied groups.