wald_test
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wald_test [2023/12/07 00:29] – hkimscil | wald_test [2023/12/07 23:51] (current) – [Wald test in logistic regression] hkimscil | ||
|---|---|---|---|
| Line 62: | Line 62: | ||
| * Terms: A vector that specifies which coefficients to test | * Terms: A vector that specifies which coefficients to test | ||
| + | ====== Wald test in logistic regression ====== | ||
| + | < | ||
| + | odds <- function(p) | ||
| + | odds.ratio <- function(p1, | ||
| + | logit <- function(p) | ||
| + | ilogit | ||
| + | |||
| + | iter <- 10000 | ||
| + | n <- 350 | ||
| + | p.cancer <- 0.08 | ||
| + | p.mutant <- 0.39 | ||
| + | |||
| + | logor <- rep (NA, iter) | ||
| + | pp0 <- rep (NA, iter) | ||
| + | pp1 <- rep (NA, iter) | ||
| + | op0 <- rep (NA, iter) | ||
| + | op1 <- rep (NA, iter) | ||
| + | or <- rep (NA, iter) | ||
| + | |||
| + | for(i in 1:iter){ | ||
| + | c <- runif(n, 0, 1) | ||
| + | canc <- ifelse(c> | ||
| + | c <- runif(n, 0, 1) | ||
| + | gene <- ifelse(c> | ||
| + | | ||
| + | da <- data.frame(gene, | ||
| + | tab <- table(da) | ||
| + | pp0[i] <- tab[1,1] / (tab[1,1] + tab[1,2]) | ||
| + | pp1[i] <- tab[2,1] / (tab[2,1] + tab[2,2]) | ||
| + | op0[i] <- odds(pp0[i]) | ||
| + | op1[i] <- odds(pp1[i]) | ||
| + | or[i] <- odds.ratio(pp0[i], | ||
| + | # stats <- c(pp0, pp1, op0, op1, ortemp) | ||
| + | logor[i] <- log(or[i]) | ||
| + | } | ||
| + | hist(logor, | ||
| + | |||
| + | |||
| + | </ | ||
wald_test.1701876581.txt.gz · Last modified: by hkimscil
