逻辑模型的观测信息矩阵

时间:2021-05-08 19:09:21

标签: r

我已经提出了我自己的模型,现在正在尝试使用 R 来实现它,我一直坚持如何应用我的公式找到观察到的矩阵我使用 glm() 来拟合带有惩罚项的逻辑模型,使用二进制数据如果 glm() 模型 def.new 是惩罚偏差,则设置 x1, x2, x3 ,y (所有二进制 0,1) fit1。

X.tilde <- as.matrix(x)                                     # n*p matrix of the data set 
W <- Diagonal(length(y), weights)                           # n*n diagonal matrix of the weights
qq <- exp(fit1$fitted.values)/(1 + exp(fit1$fitted.values)) # n*1 vector (pi=probability of the logistic model )
cc <- t(1 - qq)                                             # n*1 vector 
gg <- (dev.new) * t(dev.new)                                # p*p matrix
ff <- (X.tilde) %*% t(X.tilde)                              # n*n matrix
pp <- exp(fit1$coefficients)/(1 + exp(fit1$coefficients))   # p*1 matrix
ss <- t(1/(1 + exp(fit1$coefficients)))                     # p*1 vector
aa <- t(X.tilde) %*% qq %*% cc %*% W %*% (X.tilde)          # p*p matrix
firstP <- (aa + (pp * ss))                                  # p*p matrix
info.mat <- firstP+gg                                       # p*p matrix
info.mat <- as.matrix(info.mat)

此代码返回以下错误

<块引用>

e1 + Matrix(e2) 中的错误:
矩阵必须具有相同的算术行数

在我的理论中,当我实现它不正确时,尺寸很好 有什么帮助吗?

r

0 个答案:

没有答案