r - 包仅与 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, variables = "x", 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"
解决方案
推荐阅读
- python - 来自用户的输入未正确与数组进行比较
- scala - 将文件写入 blob 容器时在根容器中创建空文件
- nginx - 无法将 Nginx 正确配置为 Jenkins 和 Nexus 服务器的反向代理
- python - 如何解决python中的错误“列表分配索引超出范围”
- swift - 从 AppDelete 获取参考的 Swift 4.2 问题
- angular - 如何将事件发射器的值从子组件传递给父组件的函数作为参数?
- css - CSS 网格有“幽灵”空单元格 - 它们来自哪里?
- reactjs - 道具更改时使用useEffect Hook更新状态时如何修复缺少的依赖警告
- java - 将字符串数字单词转换为字符串数字:Java
- c++ - 将 std::vector 传递给构造函数而不复制