【问题标题】:Hotellings T2 in RR中的Hotelling T2
【发布时间】:2021-02-06 18:46:13
【问题描述】:

我也在尝试在 r 中使用 Hotellings T2 测试来比较两个向量。 hotellings t2 测试会自动计算我正在比较的 2 个向量的平均值,还是我自己也会这样做? 非常感谢 我正在使用的功能是 ICSNP::HotellingsT2

【问题讨论】:

  • 您好,Conor,请至少提供您尝试使用的函数的名称。函数文档也可能是查看的好地方,您可以通过调用 ?my_functionhelp("my_function") 来获取它。
  • 抱歉,我正在使用 ICSNP HotellingsT2 函数
  • 查看函数文档,输出值中未列出均值。我建议尝试运行该函数,然后自己检查输出。

标签: r statistics t-test multivariate-testing


【解决方案1】:

ICSNP::HotellingsT2() 函数返回一个htest() 类型的对象,一个包含七个项目的列表,其中没有一个是被比较对象的平均值。我们可以通过使用函数比较mtcars 数据帧中的平均mpg 按传输类型(手动或自动)来验证这一点。

library(ICSNP)
aResult <- HotellingsT2(mtcars$mpg ~ mtcars$am)
str(aResult)

...结果:

> str(aResult)
List of 7
 $ statistic  : num [1, 1] 16.9
  ..- attr(*, "names")= chr "T.2"
 $ p.value    : num [1, 1] 0.000285
 $ method     : chr "Hotelling's two sample T2-test"
 $ parameter  : Named num [1:2] 1 30
  ..- attr(*, "names")= chr [1:2] "df1" "df2"
 $ data.name  : chr "mtcars$mpg by mtcars$am"
 $ alternative: chr "two.sided"
 $ null.value : Named chr "c(0)"
  ..- attr(*, "names")= chr "location difference"
 - attr(*, "class")= chr "htest"

您可以使用base::aggregate()按组计算平均值。

aggregate(mpg ~ am,data = mtcars,mean)

> aggregate(mpg ~ am,data = mtcars,mean)
  am      mpg
1  0 17.14737
2  1 24.39231

【讨论】:

    猜你喜欢
    • 2012-08-17
    • 2019-10-07
    • 2018-03-25
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2017-05-01
    • 2014-10-14
    • 1970-01-01
    相关资源
    最近更新 更多