<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>FAQ/RTM2</title><revhistory><revision><revnumber>2</revnumber><date>2015-10-15 14:23:39</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>1</revnumber><date>2015-10-15 14:20:54</date><authorinitials>PeterWatson</authorinitials></revision></revhistory></articleinfo><section><title>Computing the regression to the mean effect?</title><para>The below example uses equation (1) of <ulink url="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/statswiki/FAQ/RTM2/statswiki/FAQ/RTM2?action=AttachFile&amp;do=get&amp;target=RTMpaper.pdf">Barnett, AG, van der Pols1, JC and Dobson, AJ (2005) 34 215-220</ulink> which uses the example below where only people with a score of 40 or below were sampled at baseline from a population with a mean of 60 and a standard deviation of 15.  </para><screen><![CDATA[* Taken from http://hisdu.sph.uq.edu.au/lsu/adrian/rtmcode.htm#Rcode
]]><![CDATA[
# Change these parameters depending on your data;
 sigma<-15; # total std;
 mu<-60; # population mean;
 cut<-40; # cut-off;
 # Loops to run through rho and m scenarios;
 sigma2_w=vector(length=11,mode="numeric")
 sigma2_b=vector(length=11,mode="numeric")
 Rl=vector(length=11,mode="numeric")
 Rg=vector(length=11,mode="numeric")
 rho=vector(length=11,mode="numeric")
 for (rhox in 0:10){
 rho[rhox+1]<-rhox/10
 sigma2_w[rhox+1]<-(1-rho[rhox+1])*(sigma^2); # within-subject variance;
 sigma2_b[rhox+1]<-rho[rhox+1]*(sigma^2); # between-subject variance;
 for (m in 1:1){ # Number of baseline measurements;
 zg<-(cut-mu)/sigma; # z;
 zl<-(mu-cut)/sigma; # z;
 x1g<-dnorm(x=zg); # phi - probability density;
 x2g<-1-pnorm(q=zg); # Phi - CDF
 x1l<-dnorm(x=zl); # phi;
 x2l<-1-pnorm(q=zl); # Phi;
 czl<-x1l/x2l; # C(z) in paper;
 czg<-x1g/x2g; # C(z) in paper;
 Rl[rhox+1]<-(sigma2_w[rhox+1]/m)/sqrt(sigma2_b[rhox+1]+(sigma2_w[rhox+1]/m))*czl; # RTM effect, Equations (1) m=1 & (2) m>1;
 Rg[rhox+1]<-(sigma2_w[rhox+1]/m)/sqrt(sigma2_b[rhox+1]+(sigma2_w[rhox+1]/m))*czg; # RTM effect;
 }
 }
 output<-cbind(sigma2_b,sigma2_w,rho,Rl,Rg)
 print("The expected RTM effect for a range of baseline samples sizes and rhos")
 print(output)
 print("sigma2_b=between-subject variance, sigma2_w=within-subject variance")
 print("rho=within-subject correlation, Rl=RTM effect (<cut-off), Rg=RTM effect (>cut-off)");]]></screen></section></article>