包仅与 S3 一起运行,“此 S4 类不可子集”

问题描述

我想将 margins 包应用于 s4 输出

library(sure) # for residual function and sample data sets
library(MASS) # for polr function
library(VGAM)
library(margins)
rm(df1)
df1 <- df1
df1$x2 <- df2$y
df1$x3 <- df2$x
df1$y <- df3$x/10

这里有两个包。一个s3 输出一个 s4

fit.polr.s3 <- polr(x2 ~ x + x3,data = df1,method = "probit") # S3
fit.polr.s4  <- vglm(x2 ~ x + x3,family=propodds,data=df1) # S4

summary(margins(fit.polr.s3,variables = "x",typ="response"))

 factor    AME     SE      z      p   lower  upper
      x 0.0011 0.0010 1.0853 0.2778 -0.0009 0.0031

但是:

summary(margins(fit.polr.s4,typ="response"))

Error in `*tmP*`[["coefficients"]] : this S4 class is not subsettable

我需要 VGAM 函数,无论如何可以将输出转换回 s3。或者让包接受s4

我很确定唯一的问题是应该如何使用 @ 而不是 $。我试图在包中替换它,但如果我在 margins 中输入 R。它只显示

function (model,...) 
{
    UseMethod("margins")
}
<bytecode: 0x000001c2ebaca028>
<environment: namespace:margins>

编辑:

运行 fit.polr.s4$coefficients <- fit.polr.s4@coefficients 给出错误Error in $<-(*tmP*,coefficients,value = c((Intercept):1 = 3.03597808578146,: no method for assigning subsets of this S4 class

> class(fit.polr.s4)
[1] "vglm"
attr(,"package")
[1] "VGAM"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)