我正在执行一项任务,其中我有一个数据框架df.3,其中我从library(MASS)中过滤了数据帧Cars93,只保留了两种4缸和6缸的汽车,或者( c1和c2类型)。
我试图用t检验来近似90%的置信区间,来计算这两种圆柱的柱Min.Price平均值之间的差异。
然而,在默认情况下,t-test将对4- 6气瓶进行比较。有没有办法得到6- 4?感谢您的帮助。
我做了如下t检验:
var.test(Min.Price ~ Cylinders, df.3)
t.test(Min.Price ~ Cylinders, df.3, conf=0.9)
t.test(df.3$Min.Price ~ df.3$Cylinders,conf=0.9)$conf.int发布于 2022-11-23 14:12:21
使用factor根据您认为合适的情况重新排序Cylinders列。或者,您可以使用rev函数。
library(MASS)
new_data <- subset(Cars93, Cylinders %in% c("4", "6"))
new_data$Cylinders_f <- factor(new_data$Cylinders, levels = c("6", "4"))
t.test(Min.Price ~ Cylinders_f, data = new_data)
Welch Two Sample t-test
data: Min.Price by Cylinders_f
t = 6.1322, df = 45.029, p-value = 1.982e-07
alternative hypothesis: true difference in means between group 6 and group 4 is not equal to 0
95 percent confidence interval:
6.112782 12.091958
sample estimates:
mean in group 6 mean in group 4
21.50645 12.40408 https://stackoverflow.com/questions/74548137
复制相似问题