Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Project2.Question1
##use source() to read file into R## #getwd() #source("C:\\Users\\kemia\\Desktop\\STA 4504\\gtest.r") #MATRIX ONE heartdisease<- matrix(c(51,22,43,92,21,28,68,9,22),nrow=3,byrow=TRUE) dimnames(heartdisease)<-list(SmokingHabits=c("Current","Former","Never"),Socioeconomic=c("High","Middle","Low")) names(dimnames(heartdisease))<-c("Smoking Habits","Socioeconomic Status") heartdisease tot<-sum(heartdisease) ##adds all cells## props<-heartdisease/tot ##proportions, joint probabilites## rowtot<-apply(heartdisease,1,sum);rowtot ##marginal probabilities## coltot<-apply(heartdisease,2,sum);coltot rowpct<-sweep(heartdisease,1,rowtot,"/");rowpct ##conditional distributions,/means divide row, pi and q## round(rowpct,3) ##round to 3 decimals## ##Pearson Chi-Squared Test chisq.test(heartdisease) chisq.test(heartdisease,simulate.p.value=4,B=10000) ##Likelihood Ratio Test AKA Gsqaure test rtot<-apply(heartdisease,1,sum);rtot ctot<-apply(heartdisease,2,sum);ctot n<-sum(heartdisease);n mu<-rtot%*%t(ctot)/n;mu #matrix multiplication df<-(nrow(heartdisease)-1)*(ncol(heartdisease)-1);df g<-2*sum(heartdisease*log(heartdisease/mu));g pval<-1-pchisq(g,df);pval ##Standard Residuals print("Standard Residual Table:") resids<-(heartdisease-mu)/sqrt(mu);resids ##Standard Adjusted Residuals print("Standard Adjusted Residual Table:") adjresids<-(heartdisease-mu)/sqrt(mu*props*(1-props));adjresids ##Partioning Chi-Square print("Table Partion of G_2") tableOne<-heartdisease[c(1,2),c(1,2)];tableOne #g.test(tableOne) print("Table Partion of G_2") tableTwo<-matrix(c(73,43,113,28),nrow=2,byrow=TRUE);tableTwo #g.test(tableTwo) print("Table Partion of G_3") tableThree<-matrix(c(143,43,68,21),nrow=2,byrow=TRUE);tableThree #g.test(tableThree) print("Table Partion of G_34") tableFour<-matrix(c(186,71,77,22),nrow=2,byrow=TRUE);tableFour #g.test(tableFour) ##95% Confidence Interval for the Odds Ratio heartdisease<-heartdisease[c(1,3),c(1,3)] heartdisease heartdisease.test<-prop.test(heartdisease) heartdisease.test$estimate heartdisease.test$estimate[1] heartdisease.test$estimate[2] odds<-heartdisease.test$estimate/(1-heartdisease.test$estimate);odds print("The odds ratio is:") odds[1]/odds[2] ##odds ratio (heartdisease[1,1]*heartdisease[2,2])/(heartdisease[1,2]*heartdisease[2,1]) theta<-odds[1]/odds[2] ase<-sqrt(sum(1/heartdisease));ase logtheta.ci<-log(theta)+c(-1,1)*1.96*ase print("confidence interval") logtheta.ci print("exponetial confidence interval") exp(logtheta.ci)
run
|
edit
|
history
|
help
0
Variance and Standard Deviation
Gab1A(resumido)
waves 2
Paired t-test [Access Medical Information]
Regressão linear
Mobile-Sprite-image-Interval
Simple Linear Regression
Distribution stable under iteration
Not able to install packages
R1