Objectres1是metafor包中的回歸函式。Objectres2是基于statsR 的回歸函式。
我想知道是否有可能獲得vcov()ofres1并將其替換為vcov()of res2?
以下是我不成功的解決方案。
# An Example:
library(metafor)
dat2 <- escalc(measure="OR", ai=waward, n1i=wtotal, ci=maward,
n2i=mtotal, data=dat.bornmann2007)
res1 <- rma.mv(yi ~ 0 type, vi, random = ~ 1 | study/obs, data=dat2)
res2 <- lm(yi ~ 0 type, data = dat2)
vcov(res2) <- vcov(res1) ## apparently this won't work!
uj5u.com熱心網友回復:
你沒有說你打算如何使用vcov()呼叫的結果,這很關鍵。如果您所做的只是呼叫vcov()并且想要不同的結果,只需將metafor物件作為物件的一個??屬性lm,為其分配一個新類(例如“lmPlusMetafor”),然后定義一個vcov.lmPlusMetafor從部件中提取結果的方法metafor。
這是執行此操作的代碼:
library(metafor)
dat2 <- escalc(measure="OR", ai=waward, n1i=wtotal, ci=maward,
n2i=mtotal, data=dat.bornmann2007)
res1 <- rma.mv(yi ~ 0 type, vi, random = ~ 1 | study/obs, data=dat2)
res2 <- lm(yi ~ 0 type, data = dat2)
attr(res2, "metafor") <- res1
class(res2) <- c("lmWithMetafor", class(res2))
vcov.lmWithMetafor <- function(object, ...) vcov(attr(object, "metafor"))
現在,當您運行時vcov(res1),vcov(res2)您將得到相同的結果。
但是,對于任何有用的東西,這可能還不夠好。例如,如果您現在運行summary(res2),我認為您會看到基于原始值的標準錯誤等,而不是 metafor 的。
如果您希望一切正常,則需要進行更多更改:您需要查看您想要的東西是如何計算的,并弄清楚如何使用這個新"lmWithMetafor"物件來完成它們。這并不容易。
uj5u.com熱心網友回復:
我不確定這是否能滿足您的需求,但是將函式分配給vcov物件可能會有所幫助?
vcov_1 <- vcov(res1)
vcov_2 <- vcov(res2)
vcov_1 <- vcov_2
> vcov_1 <- vcov(res1)
> vcov_1
typeFellowship typeGrant
typeFellowship 0.0018436986 0.0000618297
typeGrant 0.0000618297 0.0014597749
> vcov_2 <- vcov(res2)
> vcov_2
typeFellowship typeGrant
typeFellowship 0.008567784 0.00000000
typeGrant 0.000000000 0.00556906
> vcov_1 <- vcov_2
> vcov_1
typeFellowship typeGrant
typeFellowship 0.008567784 0.00000000
typeGrant 0.000000000 0.00556906
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/413838.html
標籤:
