使用R,当我运行下面的代码时,我收到一条错误消息。
代码:
library(MatchIt)
library(Zelig)
lw.y2loswt<-newcombined
matchIt.y2loswt <- matchit(y2_LOSWT ~ y0_HLTHTH + y0_THINIMP + y0_DRELAT
+ y0_DPARENT + y0_DFRIEND + y0_AGE910 + y0_RACE + y0_CATINC + y0_CATEDUC
+ y0_SOCCP + y0_PARENTS + y0_SELWT + y0_ATHCP, data = lw.y2loswt, method="full")
matchIt.y2loswt
summary(matchIt.y2loswt)
data.y2loswt.matchIt<-match.data(matchIt.y2loswt)
z.out0 <- zelig(y10_SUMSKIN ~ y2_LOSWT +y0_HLTHTH + y0_THINIMP +
y0_DRELAT + y0_DPARENT + y0_DFRIEND + y0_AGE910 + y0_RACE + y0_CATINC +
y0_CATEDUC + y0_SOCCP + y0_PARENTS + y0_SELWT + y0_ATHCP, data =
data.y2loswt.matchIt, model = "ls")
x.out0 <- setx(z.out0, y2_LOSWT = 0)
x1.out0 <- setx(z.out0, y2_LOSWT = 1)
s.out0 <- sim(z.out0, x = x.out0, x1= x1.out0)
#Error message:
#s.out0 <- sim(z.out0, x = x.out0, x1= x1.out0)
#Error in (function (classes, fdef, mtable) :
# unable to find an inherited method for function ‘sim’ for signature ‘"Zelig-#ls"’
除了该行之外,所有其他行都有效:
s.out <- sim(z.out0, x = x.out0, x1= x1.out0)
有人可以向我解释错误消息吗?谢谢!
答案 0 :(得分:0)
这可能与你加载的另一个包中存在'sim'功能有关。如果是这种情况,则该功能被“屏蔽”。
使用您要使用的包的名称,然后使用两次“:”,然后使用您要使用的特定功能的名称。在你的情况下,它变成:
s.out0 <- Zelig::sim(z.out0, x = x.out0, x1= x1.out0)
。
最佳