简体   繁体   English

r 摘要和几何平均数

[英]r summary and geometric mean

I am using the r summary function to estimate data summaries for predictors in my dataset.我正在使用 r summary函数来估计数据集中预测变量的数据摘要。

 data("TitanicSurvival")
 s <- summary(age ~ sex + survived, TitanicSurvival)
 plot(s, main ='', subtitles=FALSE)

Right now the default option, I think is set to display "arithmetic mean".现在默认选项,我认为设置为显示“算术平均值”。 How can I change this so that the summary function will estimate summaries based on geometric mean and not arithmetic mean.我怎样才能改变这一点,以便summary函数将根据几何平均值而不是算术平均值来估计摘要。 Thanks.谢谢。

Thanks,谢谢,

First, in the code you need to include loading of the packages you use.首先,您需要在代码中加载您使用的包。 I do that below, First: a function for the geometric mean:我在下面这样做,首先:几何平均值的函数:

gmean <- function(x) exp(mean(log(x)))

Then the solution:那么解决办法:

library(Hmisc)
library(carData)
data("TitanicSurvival")
s <- summary(age ~ sex + survived, 
             TitanicSurvival, fun=gmean)
plot(s, main ='', subtitles=FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM