load("choleverybody.RData")

with(choleverybody, t.test(cholest14 ~ group))


?wilcox.test

with(subset(choleverybody,group==1), wilcox.test(cholest2,cholest14,paired=TRUE))

with(subset(choleverybody,group==1), wilcox.test(cholest14,cholest2,paired=TRUE))

boxplot(subset(choleverybody,group==1)$cholest2,subset(choleverybody,group==1)$cholest14)


wilcox.test(subset(choleverybody,group==1)$cholest14,subset(choleverybody,group==2)$cholest14,paired=FALSE)

with(choleverybody, wilcox.test(cholest14 ~ group,paired=FALSE))

with(choleverybody, boxplot(cholest14 ~ group))

boxplot(subset(choleverybody,group==1)$cholest14,subset(choleverybody,group==2)$cholest14)


wilcox.test(subset(choleverybody,group==1)$cholest14,subset(choleverybody,group==2)$cholest14,paired=FALSE)[[3]]

rank(c(1,3,7,2,1))

rank(c(1,3,7,2,1))

mannwhitney<-function(first,second){
  nfirst<-length(first)
  nsecond<-length(second)
  
  
  avrankfirst<-sum(rank(c(first,second))[1:nfirst])/(nfirst)
  avranksecond<-sum(rank(c(first,second))[(nfirst+1):(nfirst+nsecond)])/(nsecond)
  pval<-wilcox.test(first,second,paired=FALSE)[[3]]
  
  return(c(avrankfirst,avranksecond,pval))
  
}


mannwhitney(subset(choleverybody,group==1)$cholest14,subset(choleverybody,group==2)$cholest14)


dice<-round(runif(500,0.5,6.5))
dice
table(dice)
?chisq.test
result<-chisq.test(table(dice))
result
?chisq.test
chisq.test(table(dice),p=c(0.1,0.1,0.1,0.1,0.1,0.5))