Ahir Bhairav Orai
Ahir Bhairav Orai

Reputation: 697

r summary and geometric mean

I am using the r summary function to estimate data summaries for predictors in my dataset.

 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. Thanks.

Thanks,

Upvotes: 2

Views: 541

Answers (1)

kjetil b halvorsen
kjetil b halvorsen

Reputation: 1228

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)

Upvotes: 3

Related Questions