<?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/dr</title><revhistory><revision><revnumber>4</revnumber><date>2013-03-08 10:17:44</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>3</revnumber><date>2012-04-24 08:51:33</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>2</revnumber><date>2012-04-24 08:51:15</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>1</revnumber><date>2012-04-24 08:47:54</date><authorinitials>PeterWatson</authorinitials></revision></revhistory></articleinfo><section><title>R code for the p-value for td obtained using Dunnett's test</title><para>The below gives R code for computing the p-value for Dunnett's test given the number of treatments, number of subjects per group and the error degrees of freedom for the group main effect. </para><para>You may need to install the mvtnorm package using </para><screen><![CDATA[install.packages("mvtnorm")]]></screen><para>The function for computing the p-value for Dunnett's test is then read in as below </para><screen><![CDATA[library('mvtnorm')
]]><![CDATA[
dunnett_p <- function(td, k, n, df)
{
        # td: Dunnett's t-statistic
        # k: number of treatments, including the reference
        # n: number of subject (assuming equal in all treatments)
        # df: degrees of freedom
        
        cMat <- rbind(-1,diag(k-1))
        corMat <- t(cMat)%*%(cMat/n)
        den    <- sqrt(crossprod(t(colSums(cMat^2/n))))
        corMat <- corMat / den
        
        p <- pmvt(lower=rep(-td, k-1), upper=rep(td, k-1), delta=rep(0, k-1), df=df, corr=corMat)
        1-p[[1]]
}]]></screen><para>The above function may then be run, for example, as below to give the p-value </para><screen><![CDATA[dunnett_p(2.3,3,5,23)]]></screen><para>[1] 0.05614953 </para></section></article>