Movatterモバイル変換


[0]ホーム

URL:


Skip to contents

Composite Scores

Source:vignettes/composite-scores.Rmd
composite-scores.Rmd
library(adoptr)

While adopt also allows implementation of custom scores viasubclassing, for most applications a simple point-wise arithmetic onscores is sufficient. For instance, consider the case of a utilitymaximizing approach to planning where not a hard constraint on power butrather a trade-off between power and expected sample size is required.The simplest utility function would just be a weighted sum of both power(negative weight since we minimize costs!) and expected sample size.

Consider the following situation

H_0<-PointMassPrior(.0,1)H_1<-PointMassPrior(.2,1)datadist<-Binomial(.1, two_armed=FALSE)ess<-ExpectedSampleSize(datadist,H_1)power<-Power(datadist,H_1)toer<-Power(datadist,H_0)

Adoptr supports suchCompositeScores via thecomposite function:

objective<-composite({ess-50*power})

The new unconditional score can be evaluated as usual, e.g.

design<-TwoStageDesign(    n1=100,    c1f=.0,    c1e=2.0,    n2_pivots=rep(150,5),    c2_pivots=sapply(1+adoptr:::GaussLegendreRule(5)$nodes,function(x)-x+2))evaluate(objective,design)#> [1] 50.16813

Note that conditional and unconditional scores cannot be mixed in anexpression passed tocomposite. Composite conditionalscore, however, are possible as well.

cp<-ConditionalPower(datadist,H_1)css<-ConditionalSampleSize()cs<-composite({css-50*cp})
evaluate(cs,design,c(0,.5,1))#> [1] 200.0014 200.0003 200.0001

Of course, composite conditional scores can also be integrated

evaluate(expected(cs,datadist,H_1),design)#> [1] 50.16813

and (due to linearity) the result is exactly the same as before.

Functional Composition

Composite scores are not restricted to linear operations but supportany valid numerical expression:

cs<-composite({log(css)-50*sin(cp)})evaluate(cs,design,c(0,.5,1))#> [1] -36.55135 -36.55192 -36.55205

Even control flow is supported:

cs<-composite({res<-0for(iin1:3){res<-res+css}res})evaluate(cs,design,c(0,.5,1))#> [1] 750 750 750

The only real constraint is that the expression must bevectorized.


[8]ページ先頭

©2009-2025 Movatter.jp