Match.arg(类型)中的错误:' arg'试图运行方差分析时必须长度为1

发布于 2025-01-25 11:23:19 字数 2868 浏览 0 评论 0原文

我正在尝试将两个GLM模型与R中的ANOVA函数进行比较,以测试它们是否变得更好或更复杂,但是当我尝试运行ANOVA时,我总是会收到此错误消息:

Error in match.arg(type) : 'arg' must be of length 1

我的代码看起来像这样:

model1 <- glm(Tempus~Typ, data=tempusB, family=binomial)

model2 <- glm(Tempus~Typ+Semantik, data=tempusB, family=binomial)

Anova(model1, model2, test="LRT")

我已经看过在ANOVA功能的“帮助”部分中,如果我正确理解,似乎使用GLM模型,我只能使用一个参数?这是这里的问题吗?这是否意味着在这种情况下不可能使用ANOVA功能?

很抱歉,如果这是一个愚蠢的问题,我是R的绝对初学者,我的教授告诉我使用ANOVA功能,所以我尝试了。

编辑:这是我数据的示例。

dput(head(tempusB)
structure(list(Tempus = structure(c(2L, 2L, 1L, 1L, 2L, 2L), .Label = c("kT", 
"T"), class = "factor"), Typ = structure(c(3L, 1L, 3L, 3L, 3L, 
3L), .Label = c("K", "M", "V"), class = "factor"), Person = structure(c(3L, 
3L, 3L, 3L, 3L, 1L), .Label = c("1", "2", "3", "U"), class = "factor"), 
    Numerus = structure(c(2L, 1L, 1L, 1L, 1L, 1L), .Label = c("PL", 
    "SG", "U"), class = "factor"), Aktionsart = structure(c(1L, 
    1L, 2L, 2L, 2L, 1L), .Label = c("dur", "perf"), class = "factor"), 
    Semantik = structure(c(3L, 3L, 1L, 1L, 1L, 1L), .Label = c("Tat", 
    "Vor", "Zust"), class = "factor"),  
    Satz = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("HS", 
    "NS"), class = "factor"), Klasse = structure(c(3L, 2L, 1L, 
    1L, 1L, 1L), .Label = c("sch", "st", "unr"), class = "factor"), 
    Thema = structure(c(2L, 2L, 5L, 5L, 2L, 1L), .Label = c("Arbeit", 
    "Familie", "Gem", "Leben", "Mission", "Pers", "PNG"), class = "factor"), 
    Speaker = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("AC", 
    "AH", "BC", "BG", "CW", "DH", "DK", "EHA", "EHI", "EMH", 
    "EP", "ESE", "EUG", "EWH", "EWO", "HT", "JC", "JE", "JHI", 
    "JL", "MCA", "MG", "MT", "PK", "RM", "VK", "VR", "WR"), class = "factor"), 
    Interviewer = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", 
    "2", "12", "13"), class = "factor"), Sprache = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L), .Label = c("SD", "UD", "UDSD"), class = "factor"), 
    Anzahl_P = c(4, 4, 4, 4, 4, 4), Geschlecht = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L), .Label = c("m", "w"), class = "factor"), 
    Alter = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("2", 
    "3"), class = "factor"), Bildung = structure(c(3L, 3L, 3L, 
    3L, 3L, 3L), .Label = c("C", "HS", "NE", "U"), class = "factor"), 
    Stolz = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a", 
    "b", "U"), class = "factor"), Identität = structure(c(3L, 
    3L, 3L, 3L, 3L, 3L), .Label = c("a", "b", "c", "U"), class = "factor"), 
    Erstsprache = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("L1", 
    "L2", "U"), class = "factor"), Englisch = c(10.56, 10.56, 
    10.56, 10.56, 10.56, 10.56)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"), na.action = structure(c(`12861` = 12861L), class = "omit"))

I am trying to compare two glm-models with the Anova Function in R to test if they are getting better or just more complex but when I try to run the Anova I always get this error message:

Error in match.arg(type) : 'arg' must be of length 1

My code looks like this:

model1 <- glm(Tempus~Typ, data=tempusB, family=binomial)

model2 <- glm(Tempus~Typ+Semantik, data=tempusB, family=binomial)

Anova(model1, model2, test="LRT")

I already looked in the help section of the Anova-Function and if I understand correctly it seems that with glm-models I can only use one argument? Is that the problem here? And does this mean it is not possible to use the Anova-Function in this case?

I am sorry if it's a dumb question, I am an absolute beginner with R and my professor told me to use the Anova-Function, so I tried.

Edit: Here is an example of my data.

dput(head(tempusB)
structure(list(Tempus = structure(c(2L, 2L, 1L, 1L, 2L, 2L), .Label = c("kT", 
"T"), class = "factor"), Typ = structure(c(3L, 1L, 3L, 3L, 3L, 
3L), .Label = c("K", "M", "V"), class = "factor"), Person = structure(c(3L, 
3L, 3L, 3L, 3L, 1L), .Label = c("1", "2", "3", "U"), class = "factor"), 
    Numerus = structure(c(2L, 1L, 1L, 1L, 1L, 1L), .Label = c("PL", 
    "SG", "U"), class = "factor"), Aktionsart = structure(c(1L, 
    1L, 2L, 2L, 2L, 1L), .Label = c("dur", "perf"), class = "factor"), 
    Semantik = structure(c(3L, 3L, 1L, 1L, 1L, 1L), .Label = c("Tat", 
    "Vor", "Zust"), class = "factor"),  
    Satz = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("HS", 
    "NS"), class = "factor"), Klasse = structure(c(3L, 2L, 1L, 
    1L, 1L, 1L), .Label = c("sch", "st", "unr"), class = "factor"), 
    Thema = structure(c(2L, 2L, 5L, 5L, 2L, 1L), .Label = c("Arbeit", 
    "Familie", "Gem", "Leben", "Mission", "Pers", "PNG"), class = "factor"), 
    Speaker = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("AC", 
    "AH", "BC", "BG", "CW", "DH", "DK", "EHA", "EHI", "EMH", 
    "EP", "ESE", "EUG", "EWH", "EWO", "HT", "JC", "JE", "JHI", 
    "JL", "MCA", "MG", "MT", "PK", "RM", "VK", "VR", "WR"), class = "factor"), 
    Interviewer = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", 
    "2", "12", "13"), class = "factor"), Sprache = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L), .Label = c("SD", "UD", "UDSD"), class = "factor"), 
    Anzahl_P = c(4, 4, 4, 4, 4, 4), Geschlecht = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L), .Label = c("m", "w"), class = "factor"), 
    Alter = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("2", 
    "3"), class = "factor"), Bildung = structure(c(3L, 3L, 3L, 
    3L, 3L, 3L), .Label = c("C", "HS", "NE", "U"), class = "factor"), 
    Stolz = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a", 
    "b", "U"), class = "factor"), Identität = structure(c(3L, 
    3L, 3L, 3L, 3L, 3L), .Label = c("a", "b", "c", "U"), class = "factor"), 
    Erstsprache = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("L1", 
    "L2", "U"), class = "factor"), Englisch = c(10.56, 10.56, 
    10.56, 10.56, 10.56, 10.56)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"), na.action = structure(c(`12861` = 12861L), class = "omit"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-02-01 11:23:19

因此,我发现了自己的错误,这是一个愚蠢的错误,但是如果其他任何人都跌跌撞撞:我已经将ANOVA和ANOVA功能互相困惑。
a nova函数(来自统计数据)与我尝试的语法一起使用:

anova(model1,model2,test =“ lrt”)

a nova函数(来自汽车包装)只需要一个模型(这就是为什么它说它只需要1个参数),因此语法将是:

anova(model1,test =“ lrt”)代码>,

就是这样。

So I found my own mistake and it was a dumb one, but in case anyone else stumbles over that: I have confused the anova and Anova-function with each other.
The anova function (from the stats-package) works with the syntax I tried:

anova(model1, model2, test="LRT")

But the Anova function (from the car-package) only needs one model (that's why it said it only needs 1 argument), so the syntax would be:

Anova(model1, test="LRT")

So that's pretty much it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文