Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7aabb44

Browse files
committed
Merge branch 'pr/5'
2 parentsb05e223 +3141c57 commit7aabb44

File tree

7 files changed

+328
-0
lines changed

7 files changed

+328
-0
lines changed

‎DESCRIPTION‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ VignetteBuilder: knitr
3030
URL: https://github.com/mcdonohue/longpower
3131
Collate:
3232
'longpower-package.R'
33+
'cprm.power.R'
3334
'diggle.linear.power.R'
3435
'edland.linear.power.R'
3536
'liu.liang.linear.power.R'

‎MD5‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
48e4f75c92a1848e138e935df130b7a7 *DESCRIPTION
2+
0173992cbaf87e097c745bc8974fdab6 *NAMESPACE
3+
1c6d8438ad946e0fe2f99964bba9bdc9 *R/diggle.linear.power.R
4+
b8d65815dcca7bc3ee20902f45f0912c *R/edland.linear.power.R
5+
caabca967f829b75bb7f5968a608ac65 *R/hu.mackey.thomas.linear.power.R
6+
e908804db408f495af7e310be2f0d772 *R/liu.liang.linear.power.R
7+
41b6d602b7849bedb2e07d9806a4c686 *R/lmmpower.R
8+
c335aab676733f3579a22a04034713ea *R/longpower-package.R
9+
377b0d010a142a1c89bb3b49d47607ba *R/power_mmrm.R
10+
d0ea6a038523d86bc4624eb7b3f9939c *R/print.power.longtest.R
11+
d9df30376ac8e90eec546c13f882d331 *build/vignette.rds
12+
82d299c9b9bc930b02956d0f2d3ca130 *inst/CITATION
13+
cb0b72c4402b6bf674c272628ef8757f *inst/doc/longpower.R
14+
bc7891a2d4096da3a99e6eeb18a62858 *inst/doc/longpower.Rmd
15+
9155d05947b16a7dccd0c9e1cf2698c6 *inst/doc/longpower.html
16+
2ebde5b6a7bca819e99c7243bbdbed31 *man/diggle.linear.power.Rd
17+
f51ce2ae6a8b499ddc45f4753e1eedef *man/edland.linear.power.Rd
18+
d7af18199815af025ec56039e7bf6d29 *man/hu.mackey.thomas.linear.power.Rd
19+
0e2550a9bc541ae09bfea770b94e97a0 *man/liu.liang.linear.power.Rd
20+
48b8e8a2366c734cea4ad5780d449040 *man/lmmpower.Rd
21+
a660e38b2832592c0e2ccdf927cba70c *man/longpower-package.Rd
22+
cb8ef61b59deaffa06900e7ab18a613d *man/power.longtest.Rd
23+
c5752686d1163ffcc91000bccf1d360d *man/power.mmrm.Rd
24+
0067a57108d2ed324da2d6a93eb38455 *man/power.mmrm.ar1.Rd
25+
abcb3796174d6222a3ee9c408e2406dc *man/print.power.longtest.Rd
26+
128cc2bce37f0eee9b987a0babb30fa2 *tests/testthat.R
27+
655c6813bd2f2fae1a210631ee82332f *tests/testthat/tests.R
28+
bc7891a2d4096da3a99e6eeb18a62858 *vignettes/longpower.Rmd
29+
dbcc5d1c7df3b3a647f88325d2d91ed3 *vignettes/longpower.bib

‎NAMESPACE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ S3method(lmmpower,gee)
66
S3method(lmmpower,lme)
77
S3method(lmmpower,numeric)
88
S3method(print,power.longtest)
9+
export(cprm.power)
910
export(diggle.linear.power)
1011
export(edland.linear.power)
1112
export(hu.mackey.thomas.linear.power)

‎R/cprm.power.R‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#' Chronic progressive repeated measures (CPRM) model sample size calculations.
2+
#'
3+
#' This function performs sample size calculations for the chronic progressive
4+
#' repeated measures (CPRM) model when used to test for differences of change scores
5+
#' between groups at last visit. Input parameters are random effect variance
6+
#' and residual error variance as estimated by a REML fit to representative
7+
#' pilot data or data from a representative prior clinical trial or cohort
8+
#' study.
9+
#'
10+
#' Default settings perform sample size / power / effect size calculations assuming
11+
#' equal covariance of repeated measures in the 2 groups, equal residual error
12+
#' variance across groups, equal allocation to groups, and assuming no study subject
13+
#' attrition. Specifically, variance parameters required for default settings
14+
#' are `sig2.s`, the variance of random slopes, and `sig2.e`, the residual error
15+
#' variance, both either known or estimated from a mixed model fit by REML
16+
#' to prior data.
17+
#'
18+
#' This function accommodates different variance parameters across groups,
19+
#' unequal allocation across groups, and study subject attrition (loss to followup),
20+
#' which may also vary across groups. Details can be found in the description of
21+
#' \code{\link{edland.linear.power}}
22+
#'
23+
#' @md
24+
#'
25+
#' @name cprm.power
26+
#' @param n sample size, group 1
27+
#' @param lambda allocation ratio (sample size group 1 divided by sample size group 2)
28+
#' @param delta group difference in fixed effect slopes
29+
#' @param t the observation times
30+
#' @param sig2.s variance of random slopes, group 1
31+
#' @param sig2.s_2 variance of random slopes, group 2 (defaults to `sig2.s`)
32+
#' @param sig2.int variance of random intercepts, group 1
33+
#' @param sig2.int_2 variance of random intercepts, group 2 (defaults to `sig2.int`)
34+
#' @param sig.b0b1 covariance of random slopes and intercepts,group 1
35+
#' @param sig.b0b1_2 covariance of random slopes and intercepts, group 2 (defaults to `sig.b0b1`)
36+
#' @param sig2.e residual variance, group 1
37+
#' @param sig2.e_2 residual variance, group 2 (defaults to `sig2.e`)
38+
#' @param p proportion vector for group 1, if i indexes visits, `p[i]` = the proportion whose last visit was at visit `i` (`p` sums to `1`)
39+
#' @param p_2 proportion vector for group 2 (defaults to `p`)
40+
#' @param sig.level type one error
41+
#' @param power power
42+
#' @param alternative one- or two-sided test
43+
#' @param tolnot used (no root finding used in this implementation).
44+
#' @return One of the number of subject required per arm, the `power`, or detectable effect size
45+
#' given `sig.level` and the other parameter estimates.
46+
#' @author Michael C. Donohue, Steven D. Edland, Yu Zhao
47+
#' @seealso [`lmmpower`], [`diggle.linear.power`], [`liu.liang.linear.power`], [`edland.linear.power`], [`hu.mackey.thomas.linear.power`]
48+
#' @references Zhao Y, Edland SD. The chronic progressive repeated measures (CPRM) model for longitudinal data.
49+
#' \emph{In process.}
50+
#' @keywords power sample size mixed effects random effects
51+
#' @examples
52+
#'
53+
#' \dontrun{
54+
#' browseVignettes(package = "longpower")
55+
#' }
56+
#' # An Alzheimer's Disease example using ADAS-cog pilot estimates
57+
#' t <- seq(0,1.5,0.25)
58+
#' cprm.power(delta=1.5, t=t, sig2.s = 24, sig2.e = 10, sig.level=0.05, power = 0.80)
59+
#'
60+
#' @export cprm.power
61+
#'
62+
cprm.power<-function(n=NULL,delta=NULL,power=NULL,t=NULL,lambda=1,
63+
sig2.int=0,sig2.s=NULL,sig.b0b1=0,sig2.e=NULL,
64+
sig2.int_2=NULL,sig2.s_2=NULL,sig.b0b1_2=NULL,sig2.e_2=NULL,
65+
sig.level=0.05,p=NULL ,p_2=NULL,
66+
alternative= c("two.sided","one.sided"),tol=NULL) {
67+
if (sum(sapply(list(n,delta,power),is.null))!=1)
68+
stop("exactly one of 'n', 'delta', and 'power' must be NULL")
69+
70+
if (!is.null(sig.level)&&!is.numeric(sig.level)|| any(0>sig.level|sig.level>1))
71+
stop("'sig.level' must be numeric in [0, 1]")
72+
73+
if (is.null(sig2.s)| is.null(sig2.e))
74+
stop("input values are required for each of sig2.s and sig2.e")
75+
76+
if (is.null(p))p=rep(c(0,1),c(length(t)-1,1))
77+
if (is.null(p_2))p_2=p
78+
79+
if (is.null(sig2.int_2))sig2.int_2=sig2.int
80+
if (is.null(sig2.s_2))sig2.s_2=sig2.s
81+
if (is.null(sig.b0b1_2))sig.b0b1_2=sig.b0b1
82+
if (is.null(sig2.e_2))sig2.e_2=sig2.e
83+
84+
if (length(t)!= length(p)| length(p)!= length(p_2))
85+
stop("t, p, and p_2 must be the same length")
86+
87+
if (sum(p)!=1| sum(p_2)!=1)
88+
stop("p and p_2 must sum to 1")
89+
90+
if ( (p[length(p)]!=1|p_2[length(p)]!=1)& (is.null(sig2.int)| is.null(sig.b0b1)) )
91+
stop("input values are required for each of sig2.int and sig.b0b1 when study subject attrition is specified using p or p_2")
92+
93+
alternative<- match.arg(alternative, c("two.sided",
94+
"one.sided"))
95+
96+
97+
ind_X<-matrix(rep(0,length(t)^2),nrow= length(t))
98+
ind_X[,1]<-1
99+
diag(ind_X)[2:length(t)]<-1
100+
101+
102+
getTerm=function(t,X,sig2.b0,sig.b0b1,sig2.b1,sig2.e,p){
103+
104+
V=matrix(rep(NA,length(t)^2),ncol=length(t))
105+
for(iin1:length(t)){
106+
for(jin1:length(t)){
107+
V[i,j]=sig2.int+(t[i]+t[j])*sig.b0b1+t[i]*t[j]*sig2.s
108+
}}
109+
diag(V)= diag(V)+sig2.e
110+
111+
term=0
112+
k.max=length(t)
113+
for(kin2:k.max){
114+
V.k=V[1:k,1:k]
115+
X.k=X[1:k,]
116+
term=term+p[k]*t(X.k)%*%solve(V.k)%*%X.k
117+
}
118+
solve(term)[length(t),length(t)]
119+
}
120+
term1=getTerm(t,ind_X,sig2.int ,sig.b0b1 ,sig2.s ,sig2.e ,p)
121+
term2=getTerm(t,ind_X,sig2.int_2,sig.b0b1_2,sig2.s_2,sig2.e_2,p_2)
122+
123+
124+
if (!is.null(n))
125+
n_2=n/lambda
126+
127+
if (is.null(sig.level)| is.null(sig2.s)| is.null(sig2.e))
128+
stop("solving for sig.level, sig2.s, or sig2.e is no longer supported")
129+
elseif (is.null(power)) {
130+
power= pnorm(sqrt(n*delta^2/(term1+term2*lambda))+qnorm(ifelse(alternative=="two.sided",sig.level/2,sig.level)))
131+
}
132+
elseif (is.null(delta)) {
133+
delta= sqrt((qnorm(ifelse(alternative=="two.sided",sig.level/2,sig.level))+qnorm(1-power))^2*(term1+term2*lambda)/n)
134+
}
135+
elseif (is.null(n)) {
136+
n= (qnorm(ifelse(alternative=="two.sided",sig.level/2,sig.level))+qnorm(1-power))^2*(term1+term2*lambda)/delta^2
137+
n_2=n/lambda
138+
}
139+
else# (Shouldn't happen)
140+
stop("internal error",domain=NA)
141+
142+
METHOD<-"Zhao and Edland, in process"
143+
structure(list(N=n+n_2,n= c(n,n_2),delta=delta,
144+
t=t,p=p,p_2=p_2,sig2.int=sig2.int,sig.b0b1=sig.b0b1,
145+
sig2.s=sig2.s,sig2.e=sig2.e,sig2.int_2=sig2.int_2,
146+
sig.b0b1_2=sig.b0b1_2,sig2.s_2=sig2.s_2,sig2.e_2=sig2.e_2,
147+
sig.level=sig.level,power=power,alternative=alternative,
148+
note="N is *total* sample size and n is sample size in *each* group",
149+
method=METHOD),class="power.longtest")
150+
}

‎build/vignette.rds‎

274 Bytes
Binary file not shown.

‎man/cprm.power.Rd‎

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎tests/testthat/tests.R‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,37 @@ test_that("lmmpower (edland)", {
220220
tolerance=1e-03)
221221
})
222222

223+
test_that("cprm.power", {
224+
meth<-'cprm'
225+
# Table 3 in Zhao and Edland (2023)
226+
expect_equal(cprm.power(n=80,t=0:6*.25,delta=3.488879,sig2.int=55.45902,
227+
sig.b0b1=13.58123,sig2.s=15.44793,
228+
sig2.e=13.63768)$power,0.7999999,
229+
tolerance=1e-03)
230+
expect_equal(cprm.power(power=0.8,t=0:6*.25,delta=3.488879,sig2.int=55.45902,
231+
sig.b0b1=13.58123,sig2.s=15.44793,
232+
sig2.e=13.63768)$n[1],80.00001,
233+
tolerance=1e-03)
234+
expect_equal(cprm.power(n=80,power=0.8,t=0:6*.25,sig2.int=55.45902,
235+
sig.b0b1=13.58123,sig2.s=15.44793,
236+
sig2.e=13.63768)$delta,3.488879,
237+
tolerance=1e-03)
238+
# Figure 3 in Zhao and Edland (2023)
239+
expect_equal(cprm.power(n=200,delta=0.25*4.0579*6*0.25,t=0:6*.25,sig2.int=55.45902,
240+
sig.b0b1=13.58123,sig2.s=15.44793,
241+
sig2.e=13.63768)$power,0.4888692,
242+
tolerance=1e-03)
243+
expect_equal(cprm.power(n=400,delta=0.25*4.0579*6*0.25,t=0:6*.25,sig2.int=55.45902,
244+
sig.b0b1=13.58123,sig2.s=15.44793,
245+
sig2.e=13.63768)$power,0.7800555,
246+
tolerance=1e-03)
247+
# random intercept only
248+
expect_equal(cprm.power(n=80,t=0:6*.25,delta=1.5,sig2.int=20,
249+
sig.b0b1=0,sig2.s=0,
250+
sig2.e=10)$power,0.5640936,
251+
tolerance=1e-03)
252+
})
253+
223254
test_that("lmmpower (hu)", {
224255
meth<-'hu'
225256
expect_equal(lmmpower(delta=1.5,t= seq(0,1.5,0.25),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp