3次ã®ã¯ãã¹è¡¨ã®ãã°ãªãã¢åæãããã£ã¨ã¹ã¿ã¤ãªãã·ã¥ï¼ç¬ï¼ã«ã§ããããããªãã¨æãã¤ã¤è²ã 試è¡é¯èª¤ããããã¾ãããããã¨ããããç ãã®ã§ä½ãããã®é¨åãã¡ã¢ãã¦ããã
# ä¸ã¤ã®å¤æ° A, B, & C ããã¨ã«ã¯ãã¹è¡¨ ### x <- table(A , B , C) ### ã¢ãã«ç·å½ããå¼ã§ãã£ããããã ### # ï¼ããããã£ã¨æ°è¡ã§ã§ããªããã®ã...ï¼ M <- NULL M[[1]] <- loglin(x, list(c(1,2,3)), param=T) M[[2]] <- loglin(x, list(c(1, 2), c(1, 3), c(2, 3)), param=T) M[[3]] <- loglin(x, list(c(1, 2), c(1, 3)), param=T) M[[4]] <- loglin(x, list(c(1, 2), c(2, 3)), param=T) M[[5]] <- loglin(x, list(c(1, 3), c(2, 3)), param=T) M[[6]] <- loglin(x, list(c(1, 2), 3), param=T) M[[7]] <- loglin(x, list(c(2, 3), 1), param=T) M[[8]] <- loglin(x, list(c(1, 3), 2), param=T) M[[9]] <- loglin(x, list(1, 2, 3), param=T) # åã¢ãã«ãå³ç¤º lab.llm <- c("[123]" ,"[12][13][23]" ,"[12][13]","[12][23]","[13][23]" ,"[12][3]" ,"[23][1]","[13][2]","[1][2][3]") names(M) <- lab.llm ### çµæã®åºå ### # på¤ã¨AICãç®åºãã¾ã hoge.p <- NULL; hoge.aic <- NULL for(i in 1:9){ hoge.p[i] <- 1-pchisq(M[[i]]$lrt, M[[i]]$df) hoge.aic[i] <- M[[i]]$pearson-2*M[[i]]$df } res <- cbind( round(hoge.p,4), hoge.aic) rownames(res) <- lab.llm colnames(res) <- c("p","AIC") res
ãã¡ãã®ãã¼ã¸ãåèã«ããã¦ããã ãã¾ãããæ·±è¬ï¼âRで対数線形モデル - きわめて個人的なR言語のメモ - R言語ユーザーグループ
12æ10æ¥è¿½è¨ãç¡æå³ã«ã¬ã©ã¬ã©ãã³ã®é¢æ°å
myloglin <- function(x){ M <- NULL M[[1]] <- loglin(x, list(c(1,2,3)), param=T) M[[2]] <- loglin(x, list(c(1, 2), c(1, 3), c(2, 3)), param=T) M[[3]] <- loglin(x, list(c(1, 2), c(1, 3)), param=T) M[[4]] <- loglin(x, list(c(1, 2), c(2, 3)), param=T) M[[5]] <- loglin(x, list(c(1, 3), c(2, 3)), param=T) M[[6]] <- loglin(x, list(c(1, 2), 3), param=T) M[[7]] <- loglin(x, list(c(2, 3), 1), param=T) M[[8]] <- loglin(x, list(c(1, 3), 2), param=T) M[[9]] <- loglin(x, list(1, 2, 3), param=T) hoge.G2 <- hoge.df <- hoge.p <- hoge.aic <- NULL for(i in 1:9){ hoge.G2[i] <- M[[i]]$pearson hoge.df[i] <- M[[i]]$df hoge.p[i] <- 1-pchisq(M[[i]]$lrt, M[[i]]$df) hoge.aic[i] <- M[[i]]$pearson-2*M[[i]]$df } hoge <- cbind(hoge.G2, hoge.df, hoge.p, hoge.aic) colnames(hoge) <- c("G^2","df","P","AIC") rownames(hoge) <- c("{123}","{12} {13} {23}" ,"{12} {13}","{12} {23}","{13} {23}" ,"{12} {3}","{23} {1}","{13} {2}" ,"{1} {2} {3}") return(hoge) }