home
HomeSearchDr. Hain Clinic website Information for Dizzy Patients MusicFLWVarious and Sundry

Dr. Hain's various/sundry has helpful information about things that Dr. Hain has discovered by trial and error.

This is part of our documentation how one can use the "open source" statistics program "R" to display testing data relevant to medicine.

Rotatory chair values according to decade.

Rchair

Compared to other tasks discussed with R, this is fairly easy.

The code for doing this is below.

setwd("../rchair")

library(ggplot2)
library(dplyr)
getwd()
## this reads a dump from download from the test_summary.php program.
rchair=read.csv("data.csv", header=TRUE, skip=6, sep=",",stringsAsFactors=FALSE)
rchair = rchair[!duplicated(rchair$SSN),]	## toss out duplicates.
rchair$Gain_TC[rchair$Gain_TC >= 999]<-NA    # recode missing Gain_TCs
#rchair$Gain_TC[rchair$Gain_TC>50]<-NA    	# recode crazy Gain_TCs
rchair$Gain_TC[rchair$Gain_TC <0]<-NA    	# recode crazy Gain_TCs
rchair$DOS1 = as.Date(rchair$DOS, format="%Y-%m-%d")
rchair$DOB1 = as.Date(rchair$DOB, format="%Y-%m-%d")
rchair$Age = as.numeric(format(rchair$DOS1, "%Y")) - as.numeric(format(rchair$DOB1, "%Y"))

rchair$decade<-rchair$Age/10
rchair$decade<-as.integer(rchair$decade)
rchair$decade[rchair$decade<1]<-NA    # recode missing crazy ages
rchair$decade[rchair$decade>9]<-NA    # recode missing crazy ages
rchair$decade<-as.factor(rchair$decade)

# simplify the dataframe names.
Gain_TC=rchair$Gain_TC
Decade=rchair$decade
rchair2=data.frame(Gain_TC,Decade)
rchair2 = na.omit(rchair2)			# Get rid of the NAs. 
#str(rchair2)

#plot(rchair$Age,rchair$Gain_TC, main="Rchair Gain-TC vs Age")
total <- sprintf("Gain*TC product vs. Decade for %d CDH dizzy patients", nrow(rchair2))
p <- ggplot(rchair2, aes(x=Decade, y=Gain_TC)) +
    geom_boxplot( fill="#69b3a2") + theme_linedraw() #c9b3a2 is a nice green

p + stat_summary(fun.y=mean, geom="point", shape=23, size=4)
p+ggtitle(total) + xlab("Decade") + theme(plot.title = element_text(hjust = 0.5))

# collect the statistics. 
f1 <- function(x) c(Mean = mean(x),  SD = sd(x), n=length(x))
#do.call(data.frame, aggregate(Gain_TC~Decade, rchair2, f1))
agg.data = do.call(data.frame, aggregate(Gain_TC~Decade, rchair2, f1))
agg.data	# print the stats.
© Copyright May 3, 2021 , Timothy C. Hain, M.D. All rights reserved.
Dr Hain's CV Clinic dizziness-and-hearing.com FLW Various and Sundry Dr. Hain's CV