【发布时间】:2020-05-04 01:38:15
【问题描述】:
我想对 R 进行 t.test。平均住院时间与同龄人组(大中型医院)之间
alos1 <- alos %>% filter(`Peer group` == "Large hospitals")
alos2 <- alos %>% filter(`Peer group` == "Medium hospitals")
Large_Medium <- alos1 %>% full_join(alos2)
Clean <- Large_Medium %>% filter(!`Average length of stay (days)`== "NP")
t.test(
peer_group ~ Average_length_of_stay
data = Clean
var.equal = TRUE
alternative = "two-sided"
)
上面的代码是我用来排序数据然后 t.test 但是我一直收到错误。
使用 Dput 作为 ronak 建议继承我的数据。
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"))
>
正确命名列后出现新错误。如下。新错误:t.test.formula 中的错误(对等组~平均停留时间(天),:分组因子必须恰好有 2 个级别
我会很感激你的帮助
【问题讨论】:
-
一般来说,发布特定的错误消息会很有帮助。但是,一个直接的解决方法是在
t.test中的每个参数之后都需要逗号。所以在每一行的末尾加一个逗号(除了最后一行)。 -
嗨瑞恩感谢您的快速回复。我把它贴在一个新问题上。 stackoverflow.com/questions/61584580/… 希望它的格式更好一点。我添加了逗号,但没有用。
-
@mishal2028 你不应该。改一下这个问题。使用
dput添加数据,而不是图像。阅读有关how to ask a good question 的信息以及如何提供reproducible example。 -
另一个请求,mishal2028:请不要假设我们愿意将数据图像转录成我们可以使用的东西。从您的图像的外观来看,虽然您没有名为
peer_group或Average_length_of_stay的列,但您的名称中看起来像是有空格。 -
您共享的
dput没有足够的数据点,但我认为您的列名错误。你的名字中没有下划线。你可以试试t.test( `Peer group` ~ `Average length of stay (days)`, data = Clean, var.equal = TRUE, alternative = "two-sided" )
标签: r