De Bekkergrob, Esther W., et al. "Sample Size Requirements for Discrete-Choice Experiments in Healthcare: a Practical Guide."The Patient: Patient-Centered Outcomes Research8.5 (2015): 373-384.
说明:本文主要翻译和搬运自上述paper,偶尔穿插本人使用的心得体会。
选择模型的一大好处就是不需要太多的样本,因为一份问卷中包含多道选择题,相当于每个被访者都被问了好多遍。如果有m道题、N个被访者,我们就能得到n*m条数据。
但这个N的值究竟如何选择呢?学界有许多经验法则(Rule of Thumb),上述paper的作者也总结了一通,之后又提出了自己的计算方法。
计算最小样本大小,首先需要准备5个“原料”:显著水平
参数的预估值是必不可少的,原因有两个:一是选择模型都是非线性的,其AVC(asymptotic variance-covariance)矩阵取决于参数的值本身;二是预估值可以作为效应量(effect size)来使用,而效应量越接近于0,找显著效应就越难,需要更多的样本,所以前期什么都不做光用0来作为预估值,后期就得找好多好多样本啦。
实验设计会直接影响AVC,进而影响参数估计的准确性。具体MNL的AVC如何构建,请参阅McFadden(1974)。AVC是一个包含了所有待估参数的方差和协方差的方阵,对角线是方差,非对角线是协方差(废话)。
原料备齐之后,就可以直接套公式。计算公式如下:
其中,
推导过程可以看这里:
https://static-content.springer.com/esm/art%3A10.1007%2Fs40271-015-0118-z/MediaObjects/40271_2015_118_MOESM2_ESM.pdfstatic-content.springer.com看起来有点复杂,我们请R来帮忙~
第一步,确定
#significance level (alpha)
test_alpha=0.05
z_one_minus_alpha<-qnorm(1-test_alpha)
第二步,确定
#statistical power level (1-beta)
test_beta=0.20
z_one_minus_beta<-qnorm(1-test_beta)
第三步,导入参数的预估值:
#initial belief about the parameter values (results from the simple pooled without pet)
parameters<-as.matrix(c(1.2, -0.1, 0.5, 0.1, 0.3, 0.1, 0.4, 0.1, 0.6, 0.1))
这一步需要注意的是,alternative-specific constant的预估值也要放进去;所有的预估值都要和实验设计中的参数顺序一一对应;as.matrix很多时候是多此一举,但后面矩阵相乘如果你遇到报错Error in %*% : 需要数值/复数矩阵/矢量参数,就把as.matrix加上吧。
第四步,告诉R你的参数个数、每道题的选项个数(要加上“什么都不选”这一项)和选择题数量:
#the DCE design
ncoefficients=10
nalts=4
nchoices=24
第五步,导入实验设计:
#load the design information
design<-as.matrix(read.csv("文件名", header=FALSE))
实验设计的矩阵可以写在excel里,但要注意,它是一行一个选项,每一行包括了该选项所有特性(attribute)的值,且不能用文字表述,要编码。最终的行数应等于每道题的(选项个数*选择题数量),列数等于参数个数。
红色笔迹涂抹的部分只是为了告诉大家每个单元格里填什么,实际导入时请删去,确保它是一个(选项个数*选择题数量)的矩阵。
为了后面不出错,建议大家在这步结束后验算一下实验设计矩阵和参数向量的维度:
dim(design)
dim(parameters)
第六步,计算AVC矩阵:
#compute the information matrix
#initialize a matrix of size ncoefficients by ncoefficients filled with zeros
info_mat=matrix(rep(0,ncoefficients* ncoefficients),ncoefficients, ncoefficients)
#compute exp(design matrix times initial parameter values)
exputilities=exp(design%*%parameters)
#loop over all choice sets
for(k_set in 1:nchoices){
#select alternatives in the choice set
alternatives=((k_set-1)*nalts+1):(k_set*nalts)
#obtain vector of choice shares within the choice set
p_set=exputilities[alternatives]/sum(exputilities[alternatives])
#also put these probabilities on the diagonal of a matrix that only contains zeros
p_diag=diag(p_set)
#compute middle term P-pp' in equation A.1 of Electronic Supplementary Material 2
middle_term<-p_diag-p_set%o%p_set
#pre-and postmultiply with the Xs from the design matrix for the alternatives in this choice set
full_term<-t(design[alternatives,])%*%middle_term%*%design[alternatives,]
#add contribution of this choice set to the information matrix
info_mat<-info_mat+full_term
}
#get the inverse of the information matrix (i.e., gets the variance-covariance matrix)
sigma_beta<-solve(info_mat, diag(ncoefficients))
其中middle term是这个式子里的:
I是费雪信息矩阵(Fisher information matrix),是AVC的逆矩阵;一共有1~S道选择题,每道选择题s都对应一个特性们的矩阵
最后一步,把上面算出来的东西代入公式,得出结果:
#use the parameter values as effect size
effectsize<-parameters
#formula for sample size calculation is n>[(z_(beta)+z_(1-alpha))*sqrt(Σγκ)/delta]^2
N<-((z_one_minus_beta + z_one_minus_alpha)*sqrt(diag(sigma_beta))/abs(effectsize))^2
在console界面打N,就能得出一列每个参数对应的最小样本量了。选出最大值,就是这个实验所需要的最小样本量。
有不对的地方,欢迎大家批评指正!