参照R中的mediation包(我用的是Package mediation version 4.5.0)的说明,是可以进行分析的,当因变量和中介变量都是二分类的时候,一定要把中介变量设置为0和1,仅使设置为因子变量也不行,说明文档为中原始文字为:“For binary response models, the 'mediator' must be a numeric variable with values 0 or 1 as opposed to a factor.”,不然就会一直报错“error in if (xhat==0) out <-1 else { missing value where TRUE/FALSE....”;同时在建立前期的两个方程的时候需要都使用glm;其它的设置就按照常规的来就好~