[英]Levene test in R for the datafram below
dput(head(Clean, 100))
structure(list(`Reporting unit` = c("Albury Wodonga Health [Albury Campus]",
"Albury Wodonga Health [Albury Campus]", "Albury Wodonga Health [Albury Campus]",
"Albury Wodonga Health [Albury Campus]", "Albury Wodonga Health [Albury Campus]",
"Albury Wodonga Health [Albury Campus]", "Albury Wodonga Health [Albury Campus]",
"Albury Wodonga Health [Albury Campus]", "Albury Wodonga Health [Albury Campus]",
"Albury Wodonga Health [Albury Campus]"), `Reporting unit type` = c("Hospital",
"Hospital", "Hospital", "Hospital", "Hospital", "Hospital", "Hospital",
"Hospital", "Hospital", "Hospital"), State = c("NSW", "NSW",
"NSW", "NSW", "NSW", "NSW", "NSW", "NSW", "NSW", "NSW"), `Local Hospital Network (LHN)` = c("Albury Wodonga Health",
"Albury Wodonga Health", "Albury Wodonga Health", "Albury Wodonga Health",
"Albury Wodonga Health", "Albury Wodonga Health", "Albury Wodonga Health",
"Albury Wodonga Health", "Albury Wodonga Health", "Albury Wodonga Health"
), `Peer group` = c("Large hospitals", "Large hospitals", "Large hospitals",
"Large hospitals", "Large hospitals", "Large hospitals", "Large hospitals",
"Large hospitals", "Large hospitals", "Large hospitals"), `Time period` = c("2011–12",
"2012–13", "2013–14", "2014–15", "2015–16", "2016–17", "2011–12",
"2012–13", "2013–14", "2014–15"), Category = c("Cellulitis",
"Cellulitis", "Cellulitis", "Cellulitis", "Cellulitis", "Cellulitis",
"Chronic Obstructive Pulmonary Disease (without complications)",
"Chronic Obstructive Pulmonary Disease (without complications)",
"Chronic Obstructive Pulmonary Disease (without complications)",
"Chronic Obstructive Pulmonary Disease (without complications)"
), `Total number of stays` = c(111, 116, 141, 155, 210, 196,
109, 116, 75, 132), `Number of overnight stays` = c(92, 98, 115,
123, 166, 155, 108, 113, 71, 122), `Percentage of overnight stays` = c(0.83,
0.84, 0.82, 0.79, 0.79, 0.79, 0.99, 0.97, 0.95, 0.92), `Average length of stay (days)` = c(3.9,
3.3, 3.1, 2.5, 2.6, 2.7, 5.8, 4.6, 5.7, 4.4), `Peer group average (days)` = c(3.7,
3.5, 3.3, 3.2, 3, 3, 4.8, 4.4, 4.2, 3.9), `Total overnight patient bed days` = c(356,
326, 351, 306, 431, 418, 622, 518, 405, 538)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
Hi I'm trying to do a levene test for the above data frame between the peer group (large and medium hospitals) and Average length but I get the following error:嗨,我正在尝试对对等组(大中型医院)和平均长度之间的上述数据框进行 levene 测试,但出现以下错误:
Error in leveneTest.formula(Clean$group ~ Clean$
Average length of stay (days)
, : Levene's test is not appropriate with quantitative explanatory variables. leveneTest.formula 中的错误(Clean$group ~ Clean$Average length of stay (days)
,:Levene 的测试不适用于定量解释变量。
Can someone help, please.有人可以帮忙吗?
Reverse the order in your formula:颠倒公式中的顺序:
leveneTest(Clean$`Average length of stay (days)`~Clean$`Peer group`)
The fiollowing can solve the problem.后续可以解决问题。
data
.如果使用公式接口,则不需要其中的 data.frame 名称,只需在参数data
中。 And since the package where leveneTest
might not be loaded, I prefix the function call.由于leveneTest
可能无法加载 leveneTest,因此我在 function 调用前加上前缀。
car::leveneTest(`Average length of stay (days)` ~ `Peer group`, data = Clean)
Also, the column names are not syntactically valid, spaces in the names need back ticks.此外,列名在语法上无效,名称中的空格需要反引号。
names(Clean) <- make.names(names(Clean))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.