- chicroise<-croise
- for (i in 1:nrow(croise)) {
- for (j in 1:ncol(croise)) {
- if (croise[i,j]==0) {
- chicroise[i,j]<-0
- } else if (croise[i,j]<mincl) {
- chicroise[i,j]<-0
- } else {
- chitable<-matrix(ncol=2,nrow=2)
- chitable[1,1]<-croise[i,j]
- chitable[1,2]<-poids1[i]-chitable[1,1]
- chitable[2,1]<-poids2[j]-chitable[1,1]
- chitable[2,2]<-nrow(classeuce1)-poids2[j]-chitable[1,2]
- chitest<-chisq.test(chitable,correct=FALSE)
- if ((chitable[1,1]-chitest$expected)<0) {
- chicroise[i,j]<--round(chitest$statistic,digits=7)
- } else {
- chicroise[i,j]<-round(chitest$statistic,digits=7)
- #print(chitest)
- }
+ print('croise chi2')
+ #chicroise<-croise
+
+# nr <- nrow(classeuce1)
+# newchicroise <- function(croise, mincl, nr, poids1, poids2) {
+# chicroise <- croise
+# chicroise[which(croise < mincl)] <- 0
+# tocompute <- which(chicroise > 0, arr.ind = TRUE)
+# for (i in 1:nrow(tocompute)) {
+# chitable <- matrix(ncol=2,nrow=2)
+# chitable[1,1] <- croise[tocompute[i,1], tocompute[i,2]]
+# chitable[1,2] <- poids1[tocompute[i,1]] - chitable[1,1]
+# chitable[2,1] <- poids2[tocompute[i,2]] - chitable[1,1]
+# chitable[2,2] <- nr - poids2[tocompute[i,2]] - chitable[1,2]
+# chitest<-chisq.test(chitable,correct=FALSE)
+# chicroise[tocompute[i,1], tocompute[i,2]] <- ifelse(chitable[1,1] > chitest$expected[1,1], round(chitest$statistic,digits=7), -round(chitest$statistic,digits=7))
+# }
+# chicroise
+# }
+#
+
+
+ dochicroise <- function(croise, mincl) {
+ chicroise <- croise
+ for (i in 1:nrow(croise)) {
+ for (j in 1:ncol(croise)) {
+ if (croise[i,j]==0) {
+ chicroise[i,j]<-0
+ } else if (croise[i,j]<mincl) {
+ chicroise[i,j]<-0
+ } else {
+ chitable<-matrix(ncol=2,nrow=2)
+ chitable[1,1]<-croise[i,j]
+ chitable[1,2]<-poids1[i]-chitable[1,1]
+ chitable[2,1]<-poids2[j]-chitable[1,1]
+ chitable[2,2]<-nrow(classeuce1)-poids2[j]-chitable[1,2]
+ chitest<-chisq.test(chitable,correct=FALSE)
+ if ((chitable[1,1]-chitest$expected[1,1])<0) {
+ chicroise[i,j]<--round(chitest$statistic,digits=7)
+ } else {
+ chicroise[i,j]<-round(chitest$statistic,digits=7)
+ #print(chitest)
+ }
+ }
+ }
+ }
+ chicroise
+ }
+
+ dochicroisesimple <- function(croise, mincl) {
+ chicroise <- croise
+ for (i in 1:nrow(croise)) {
+ for (j in 1:ncol(croise)) {
+ if (croise[i,j]==0) {
+ chicroise[i,j]<-0
+ } else if (croise[i,j]<mincl) {
+ chicroise[i,j]<-0
+ } else {
+ chitable<-matrix(ncol=2,nrow=2)
+ chitable[1,1]<-croise[i,j]
+ chitable[1,2]<-poids1[i]-chitable[1,1]
+ chitable[2,1]<-poids1[j]-chitable[1,1]
+ chitable[2,2]<-nrow(classeuce1)-poids1[j]-chitable[1,2]
+ chitest<-chisq.test(chitable,correct=FALSE)
+ if ((chitable[1,1]-chitest$expected[1,1])<0) {
+ chicroise[i,j]<--round(chitest$statistic,digits=7)
+ } else {
+ chicroise[i,j]<-round(chitest$statistic,digits=7)
+ #print(chitest)
+ }
+ }
+ }