DOI: 10.5281/zenodo.2615735
title: Code and data archive for Nettle et al. 'Consequences of measurement error in qPCR telomere data: A simulation study'

description: Code and data for Nettle et al. 'Consequences of measurement error in qPCR telomere data: A simulation study'

Updated version of March 2019

Main simulation functions are contained in the script ‘simulation.functions.r’. When called, these functions (listed below) return datasets with requested properties containing both the ideal values of the quantities (Cqs, TS, etc.), and their post-error measured values. This allows the user to determine the differences between ideal and measured values, and perform other analyses. All simulation parameter values are user-specifiable. The script ‘paper.results.r’ reproduces all the figures and simulation results from the main paper. 'paper.results.r' also reads in the two .csv files of empirical data (dataset1 and dataset2).

Datasets consist of observations from <em>n</em> individuals. The steps common to all of the simulation functions are as follows:


	A vector of <em>n </em>true single copy gene abundances, <em>true.dna.scg</em> is defined, drawn from a normal distribution with mean <em>b</em> and standard deviation <em>var.sample.size</em> (<em>b </em>is a constant).
	A vector of <em>n </em>relative telomere lengths, <em>true.telo.var</em> is defined, drawn from a normal distribution with mean 1 and standard deviation <em>telomere.var.</em>
	Hence, the true abundance of the telomere sequence is defined, as <em>a*true.dna.scg*true.telo.var</em>. Here, <em>a</em> is a scaling constant representing how many copies of the telomeric sequence there are per single copy gene in the average sample.
	Ideal Cq values for both reactions are defined as <em>f – log<sub>2</sub>(true.dna.scg)</em> and <em>f – log<sub>2</sub>(true.dna.telo),</em> where <em>f</em> is a constant representing the chosen fluorescence threshold.
	Measurement errors in the Cqs are generated from a normal distribution with mean 0; standard deviations given by <em>error.scg</em> and <em>error.telo</em>; and a correlation between <em>error.scg</em> and <em>error.telo</em> given by <em>error.cor</em>.
	Hence, measured Cqs are generated, which can be compared to the ideal Cq values.
	TS ratios are calculated both on the measured Cqs, and the ideal ones.


The following functions are available. Specify desired parameter values in the parenthesis, e.g. <em>generate.one.dataset(n=10000, error.telo=0.1, error.scg=0.1, error.cor=0</em>). Default values in the simulation functions are generally those given in table 1 of the main paper.


	<em>generate.one.dataset()</em> returns a simple dataset (one telomere measurement per individual) for chosen values of all the variables described in section 1. As well as ideal and measured Cqs, it returns ideal and measured TS ratios. It also returns the difference between the ideal and measured TS ratio, calculated two ways, computed (<em>error.computed</em>), and using equation (11) of online supplement 1 (<em>error.analytic</em>). Both methods produce the same number. This was included as an additional check of correctness of the simulation.
	<em>generate.repeated.measure()</em> returns a dataset where telomere lengths from the same individuals are measured twice, via two independent biological samples, and the true telomere length of each individual is assumed not to have changed at all. The data frame it returns is as for <em>generate.one.dataset()</em>, except that there are two of each variable (e.g. <em>true.ts.1, true.ts.2, measured.ts.1, measured.ts.2</em>, etc.).
	<em>calculate.repeatability()</em> calculates the repeatability of the measured T/S ratio (intra-class correlation coefficient) when <em>generate.repeated.measure()</em> is implemented using the given values for all the parameters. It requires prior installation of R package ‘irr’.
	<em>compare.repeatability()</em> returns the repeatability of the T/S ratio and the repeatability calculated on the raw Cq for the telomere reaction, for the given parameter values.