A.
解决这个问题的方法(不是唯一的方法,可能不是最有效或最紧凑的方法)是对变换空间中的参数进行一般的最大似然估计;可能最常见的这种转换是
加性对数比变换
(例如,如
compositions::alr()
). 此解决方案使用
bbmle
包装,这是一个包装
optim()
; 在这种情况下,与直接使用相比,它实际上并没有提供那么多优势
optim()
library(bbmle)
library(compositions)
linkfun <- function(mu) as.numeric(compositions::alr(mu))
invlink <- function(eta) as.numeric(compositions::alrInv(eta))
## negative log-likelihood function: first convert the parameter vector
## from the constrained (alr) space to the unconstrained space, then
## convert the linear predictor from an unconstrained space to the
## constrained (probability, (0,1)) space
lfun <- function(beta) {
-sum(dbinom(Y, size=1,
prob = plogis(as.matrix(X) %*% invlink(beta)),
log=TRUE))
}
npar <- ncol(X)
使用
mle2
:
## extra setup for using mle2 with a score function that takes a vector
## parameter
pnm <- paste0("beta", seq(npar))
parnames(lfun) <- pnm
m1 <- mle2(lfun, start = setNames(rep(0, npar-1), pnm[-1]), vecpar = TRUE)
invlink(coef(m1))
## [1] 4.897617e-01 2.221793e-01 1.274830e-05 2.198596e-05 7.541545e-02
## [6] 1.175966e-01 1.590407e-05 4.662563e-02 4.825376e-02 1.170077e-04
或
opt <- optim(par = rep(0, npar-1), fn = lfun, method = "BFGS")
invlink(opt$par)
注1
我的模型拟合与您用于生成数据的方法不匹配(这将在公式中编码为
~ 0 + x1 + x2 + x3 + x3:x4 + abs(x4)
),但你的
SuperLearner
例如,所以我并不担心。
注2
我的猜测(未经仔细考虑)是,上述方法将
不
给出与使用相同的结果
超级学习者
; 看看代码,什么
超级学习者
做的是找到(加权)最小二乘问题的非负解,然后通过将系数向量除以其和将系数转换到组合空间。这是
不一样
作为解决参数被约束为非负并且总和为1的最小偏差/最大似然问题。如果你想要
超级学习者
解决方案,通过传递适当的
method=
的论点
glm
,但我不知道如何使用
glm
.