title: R语言-有序分类logistic回归 tags: [] id: '1688' categories:
f_TCGA_gleason_grade <- function(primary_gleason_grade, secondary_gleason_grade){
primary_gleason_grade <- as.numeric(unlist(data.frame(strsplit(primary_gleason_grade, ' '))[2,]))
secondary_gleason_grade <- as.numeric(unlist(data.frame(strsplit(secondary_gleason_grade, ' '))[2,]))
primary_gleason_grade + secondary_gleason_grade
}
f_rank_transformation_o <- function(lo){
lo <- unlist(lo)
idx <- order(lo, decreasing = F)
idm <- as.data.frame(table(lo))
idm <- idm[idm$Freq>1, ]
idm <- idm[[1]]
for(i in idm){
ii <- (lo == i)
idx[ii] <- mean(idx[ii])
}
names(idx) <- names(lo)
idx
}
f_SCE_VlnBoxPlot_gD <- function(featureN, assayN='TPM', rank_trans=F, rmZero=NULL, log_trans=T, ...){
sceList <- list(...)
df <- data.frame()
for(name in names(sceList)){
sce <- sceList[[name]]
idx <- rowRanges(sce)$external_gene_name == featureN
tmp <- assay(sce[idx, ], assayN)
tmp <- data.frame(groupN=name, value=tmp[1,])
df <- rbind(df, tmp)
}
if(log_trans){
df$value <- log1p(df$value)
}
if(rank_trans){
df$value <- f_rank_transformation_o(df$value)
df
}else{
if(!is.null(rmZero)){
df[df$value>rmZero, ]
}else{df}
}
}
d <- f_SCE_VlnBoxPlot_gD('SMC4', prad_p=prad_p)
d['gleason'] <- f_TCGA_gleason_grade(prad_p$primary_gleason_grade, prad_p$secondary_gleason_grade)
saveRDS(d, 'prad_p_gleason.rds')
require(foreign)
require(ggplot2)
require(MASS)
require(Hmisc)
require(reshape2)
dat <- readRDS('prad_p_gleason.rds')
m <- polr(factor(gleason) ~ value, data = dat, Hess = TRUE)
m
drop1(m,test="Chi")
(ci <- confint(m))
exp(cbind(OR = coef(m), ci))