R logistic模型的观测信息矩阵
我已经提出了我自己的模型,现在正试图用R实现它,我一直在研究如何使用我的公式找到观测矩阵。我使用glm()来拟合带有惩罚项的逻辑模型,使用二进制数据集x1,x2,x3,y(所有二进制0,1)fit1,如果glm()模型def.new是惩罚偏差R logistic模型的观测信息矩阵,r,R,我已经提出了我自己的模型,现在正试图用R实现它,我一直在研究如何使用我的公式找到观测矩阵。我使用glm()来拟合带有惩罚项的逻辑模型,使用二进制数据集x1,x2,x3,y(所有二进制0,1)fit1,如果glm()模型def.new是惩罚偏差 X.tilde <- as.matrix(x) # n*p matrix of the data set W <- Diagonal(length(y), weights
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)
X.tilde您能否更新您的问题,请参考您问题中的评论?如果没有其他详细信息,我们仍然无法回答此问题。谢谢仅仅从你给出的维度来看;如果一个向量是nx1(例如qq),那么它的转置将不是nx1。。。所以我们真的需要一个可复制的例子