RQ1: depicting longpower and MBESS functions for design
These are hard to use as is often the case with sample size calculations.
One way I would tackle this is to just create artificial data that
I would need to guess at the same sorts of quntities to create.
The use confint to see (by increasing the sample size of the data)
when I had about enough accuracy.
R version 3.0.3 (2014-03-06) -- "Warm Puppy"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
> install.packages("longpower")
Installing package into ‘C:/Users/rag/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'http://cran.cnr.Berkeley.edu/bin/windows/contrib/3.0/longpower_1.0-10.zip'
Content type 'application/zip' length 248121 bytes (242 Kb)
opened URL
downloaded 242 Kb
package ‘longpower’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\rag\AppData\Local\Temp\RtmpWSscaj\downloaded_packages
> #as suggest on the class web page try browseVignettes(package = "longpower")
> library(longpower)
Loading required package: Matrix
Loading required package: lme4
Loading required package: lattice
Loading required package: nlme
Attaching package: ‘nlme’
The following object is masked from ‘package:lme4’:
lmList
> #as noted in class power calcs whether the simpler power.t.test or the more complex here
> # require the input of many quatities one does not know
> # take up the specs for the second ex in the vignette for Alzheimers (p.4 onward)
### implementation of longpower, required input
> # var of random intercept
> sig2.i = 55
> # var of random slope
> sig2.s = 24
> # residual var
> sig2.e = 10
> # covariance of slope and intercep
> cov.s.i <- 0.8*sqrt(sig2.i)*sqrt(sig2.s)
> # covariance matrix for observables (like week 4 Properties of Collections of Growth Curves)
> cov.t <- function(t1, t2, sig2.i, sig2.s, cov.s.i){
+ sig2.i + t1*t2*sig2.s + (t1+t2)*cov.s.i
+ }
>
> t = seq(0,1.5,0.25)
> n = length(t)
> R = outer(t, t, function(x,y){cov.t(x,y, sig2.i, sig2.s, cov.s.i)})
> R = R + diag(sig2.e, n, n)
> u = list(u1 = t, u2 = rep(0,n))
> v = list(v1 = cbind(1,1,rep(0,n)),
+ v2 = cbind(1,0,t))
d is the actual effect size for the intervention , set to 1.5
> liu.liang.linear.power(d=1.5, u=u, v=v, R=R, sig.level=0.05, power=0.80)
Longitudinal linear model power calculation (Liu & Liang, 1997)
N = 414.6202
n = 207.3101, 207.3101
delta = 1.5
sigma2 = 1
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: N is total sample size and n is sample size in each group.
R:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 65.00000 62.26636 69.53272 76.79908 84.06544 91.3318 98.59817
[2,] 62.26636 81.03272 79.79908 88.56544 97.33180 106.0982 114.86453
[3,] 69.53272 79.79908 100.06544 100.33180 110.59817 120.8645 131.13089
[4,] 76.79908 88.56544 100.33180 122.09817 123.86453 135.6309 147.39725
[5,] 84.06544 97.33180 110.59817 123.86453 147.13089 150.3972 163.66361
[6,] 91.33180 106.09817 120.86453 135.63089 150.39725 175.1636 179.92997
[7,] 98.59817 114.86453 131.13089 147.39725 163.66361 179.9300 206.19633
###################################### Now try the Ken Kelley function
> library(MBESS)
> ## this is a little less obscure in what it requires; see the supporting docs
#Suppose that a researcher would like to plan sample size so that
#the straight-line change coefficient has an expected 95% confidence
#interval width of 0.025 units, which the researcher believes
#is sufficiently narrow for the purposes of establishing an accurate
#difference between a treatment group and a control group. The
#study will have a duration of 4 years with one measurement
#occasions per year, for a total of five measurement occasions. The
#supposed variance of the linear trend (i.e.,
# of 0.003 and the supposed error variance of 0.0262, both of which are obtained
#from literature
> ss.aipe.pcm(true.variance.trend =0.003,
+ error.variance=0.0262, duration=4,
+ frequency=1, width=0.025, conf.level=.95)
[1] "Results for expected width to be sufficiently narrow"
[1] 278
# that's per group as this calculates for a single group
# An example used in Kelley and Rausch for the expected confidence interval
# width (returns 278). Thus, a necessary sample size of 278 is required when
# the duration of the study will be 4 units and the frequency of measurement
# occasions is 1 year in order for the expected confidence interval
# width to be 0.025 units.
ss.aipe.pcm(true.variance.trend=0.003, error.variance=0.0262, duration=4,
frequency=1, width=0.025, conf.level=.95)
# Now, when incorporating an assurance paramether (returns 316).
# Thus, a necessary sample size of 316 will ensure that the 95% confidence
# interval will be sufficiently narrow (i.e., have a width less than .025 units)
# at least 99% of the time.
ss.aipe.pcm(true.variance.trend=.003, error.variance=.0262, duration=4,
frequency=1, width=.025, conf.level=.95, assurance=.99)