Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
In Class Project2
\\Project 2\\ #R version 3.3.2 #computing marginal, joint, and conditional probablities afterlife<- matrix(c(435,147,375,134),nrow=2,byrow=TRUE);afterlife dimnames(afterlife)<-listc("Female","Male"),c("Yes","No")) #to look nice names(dimnames(afterlife))<-c("Gender","Believer") afterlife tot<-sum(afterlife);tot #adds all cells afterlife/tot #proportions, joint probabilites rowtot<-apply(afterlife,1,sum);rowtot #marginal probabilities #A[row,columns] #apply..name of matrix,1 means row/2 means column coltot<-apply(afterlife,2,sum);coltot rowpct<-sweep(afterlife,1,rowtot,"/");rowpct #conditional distributions,/means divide row, pi and q round(rowpct,3) #round to 3 decimals #difference in proportions, RR, odds, odds ratio phs<-matrix(c(189,10845,104,10933,ncol=2,byrow=T);phs dimnames(phs)<-list(Group=c("Placebo","Aspirin"),MI=c("Yes","No")) #to look nice phs prop.test(phs) #RR=pi1/pi2, RR^=p1/p2 phs.test<-prop.test(phs) names(phs.test) #all the things you can extract from the test phs.test$statistic phs.test$conf.int phs.test$estimate #gives a vector phs.test$estimate[1]/phs.test$estimate[2] #RR odds<-phs.test$estimate/(1-phs.test$estimate);odds odds[1]/odds[2] #odds ratio (phs[1,1]*phs[2,2]/(phs[2,1]*phs[1,2]) #theta hat n11n22/n12n21 phs theta<-odds[1]/odds[2] ase<-sqrt(sum(1/phs));ase logtheta.ci<-log(theta)+c(-1,1)*1.96*are logtheta.ci exp(logtheta.ci) #Chi square test, G square test, Fishers exact test gendercap<-matrix(c(279,73,225,165,47,191),byrow=TRUE,nrow=2) dimnames(gendercap)<-list(Gender=c("Females","Males"),PartyID=c("Democrat","Independent","Republican")) gendercap chisq.test(gendercap) chisq.test(gendercap,simulate.p.value=TRUE,B=10000) #Gsqaure test rtot<-apply(gendercap,1,sum);rtot ctot<-apply(gendercap,2,sum);ctot n<-sum(gendercap);n mu<-rtot%*%t(ctot)/n;mu #matrix multiplication df<-(nrow(gendercap)-1)*(ncol(gendercap)-1);df g<-2*sum(gendercap*log(gendercap/mu));g pval<-1-pchisq(g,df);pval #use source() to read file into R source("gtest.r") g.test(gendercap) #helpful for partioning #Fishers Test tea<-matrix(c(3,1,1,3), ncol=2) dimnames(tea)<-list(Poured=c("milk","tea"),Guess=c("milk","tea") tea fisher.test(tea) fisher.test(tea,alternative="greater")
run
|
edit
|
history
|
help
0
matrix
Otavio-fez
calc
5 # SUMMARY PART A
ExDecaiEulerMin24-02-21
Quartile Formula
Chev-nodes
Pendulum Experiment
Ass2 q2
Paired t-test_Unequal variances [Pipeline Networks]