R语言-有序分类logistic回归

第一步 获得数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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}
}
}
1
2
3
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')

第二步 更换内核进行分析

1
2
3
4
5
6
7
require(foreign)
require(ggplot2)
require(MASS)
require(Hmisc)
require(reshape2)

dat <- readRDS('prad_p_gleason.rds')
1
2
3
4
5
m <- polr(factor(gleason) ~ value, data = dat, Hess = TRUE)
m
drop1(m,test="Chi")
(ci <- confint(m))
exp(cbind(OR = coef(m), ci))

R语言-有序分类logistic回归
https://b.limour.top/1688.html
Author
Limour
Posted on
February 18, 2022
Licensed under