setwd("C:/Users/shouhermione/Documents/TA/Nanjing/Karen") osteo=read.csv('osteo.csv') #show the variable names names(osteo) ####1 #a boxplot of age #do by hand median(osteo$Age) boxplot(osteo$Age,main='Boxplot of age') #b mean,sd,leaf plot case=osteo[which(osteo$Osteo==1),]$DPA control=osteo[which(osteo$Osteo==0),]$DPA c(mean(case),mean(control)) c(sd(case),sd(control)) stem(case) stem(control) #Qc. median/interquartile range for the each osteo group c(median(case),median(control)) #IQR c(sum(c(-1,1)*summary(case)[c(2,5)]),sum(c(-1,1)*summary(control)[c(2,5)])) #boxplot by group boxplot(osteo$DPA~osteo$Osteo,main='Boxplot of DPA by osteo group') ###2 assign X #a. X=(osteo$DPA<=0.8)+(osteo$DPA<=0.9)+(osteo$DPA<=0.95)+(osteo$DPA<=1) X=5-X #density of X, round to the 3rd decimal place p=round(table(X)/length(X),digit=3) #cdf of X #compute the cumulative probability Fn<-ecdf(X) #cumulative probability pcdf<-summary.stepfun(Fn)[2:6] plot(Fn,main='ECDF of X') #mean of X mean(X) ##########Question 3 #sketch f_X and F_X f_X<-function(x){ y=0 if((x<=8)&(x>=0)) y=0.025*x if(((x>=8)&(x<=10))) y=0.200-.100*(x-8) y } sample_x=seq(from=-1,to=12,by=1) sample_y=unlist(sapply(sample_x,f_X)) #sketch f_X plot(sample_x,sample_y,type='l',xlab='X',ylab='density of X') #sketch F_X