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,
CodePudding user response:
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)