English 中文(简体)
多个 co合体的无固定 co回归分析
原标题:Univariate cox regression analysis with multiple covariates
covariates <- c("age", "sex",  "ph.karno", "ph.ecog", "wt.loss")
univ_formulas <- sapply(covariates,
                    function(x) as.formula(paste( Surv(time, status)~ , x)))
                   
univ_models <- lapply( univ_formulas, function(x){coxph(x, data = lung)})
# Extract data 
univ_results <- lapply(univ_models,
                   function(x){ 
                      x <- summary(x)
                      p.value<-signif(x$wald["pvalue"], digits=2)
                      wald.test<-signif(x$wald["test"], digits=2)
                      beta<-signif(x$coef[1], digits=2);#coeficient beta
                      HR <-signif(x$coef[2], digits=2);#exp(beta)
                      HR.confint.lower <- signif(x$conf.int[,"lower .95"], 2)
                      HR.confint.upper <- signif(x$conf.int[,"upper .95"],2)
                      HR <- paste0(HR, " (", 
                                   HR.confint.lower, "-", HR.confint.upper, ")")
                      res<-c(beta, HR, wald.test, p.value)
                      names(res)<-c("beta", "HR (95% CI for HR)", "wald.test", 
                                    "p.value")
                      return(res)
                      #return(exp(cbind(coef(x),confint(x))))
                     })
res <- t(as.data.frame(univ_results, check.names = FALSE))
as.data.frame(res)

通常,我使用这一法典进行互不相干的 co退学分析,但我有多种基因和特有;20000,我想作为独立的变数,进行无休止的牛群退学分析,我不肯定,我如何能够在不打上单个 co子(基因名)的情况下操作这一法典。 我所有的基因组名都从“ENSG”开始。

Is there a way to do univariate cox regression on so many genes in an efficient way please? Thanks in advance.

问题回答

有几个方法可以将可变姓名清单删除,而不必加以打断。 或许最容易的是使用<代码> 姓名/代码>,以获取数据中的所有变量名称,然后删除<代码> 日和<编码><>。 该清单中(以及你不想包含的任何其他变量)。 例如,<代码>veteran 数据集:

covariates <- names(survival::veteran)
covariates # Look at which names were detected
#> [1] "trt"      "celltype" "time"     "status"   "karno"    "diagtime" "age"     
#> [8] "prior"
covariates <- covariates[-which(covariates %in% c("time", "status"))]
covariates # Confirm time and status have been removed
#> [1] "trt"      "celltype" "karno"    "diagtime" "age"      "prior"

Created on 2022-08-30 by the reprex package (v2.0.1)

你们也可以从方案上制定一份名单。 例如:

covariates <- sapply(1:10, FUN = function(x) paste0("ENSG.", x))
covariates
#>  [1] "ENSG.1"  "ENSG.2"  "ENSG.3"  "ENSG.4"  "ENSG.5"  "ENSG.6"  "ENSG.7" 
#>  [8] "ENSG.8"  "ENSG.9"  "ENSG.10"

This approach might be better if the naming is easy to program. If the gene names are irregular it might be more difficult.

就效率而言,我认为改进整个运行时间还有很多工作要做。 大部分操作时间是实际进行的<编码>coxph()计算。 该网站还有关于优化区域代码的其他问题/回答。 如果你想要追求最佳化,我就建议通过这些办法,然后提出一个新问题,如果你需要更多的帮助的话,就是一个可再生的例子。

you already did it. If you check the univ_formula (like univ_formula[1], and so on), then you can see it contains each term (covariate) independently.

对于您的基因数据,你可以修改var合变量,其余数据相同:

缩略语

#The following will create (paste) formula variable containing formula and gene name:

univ_formulas <- sapply(covariates, function(x) as.formula(paste( Surv(time, status)~ , x)))

The rest is the same as you used to do.

还有一揽子计划(基因SA;)。 这也可以使用。





相关问题
Multi-variate regression using NumPy in Python?

Is it possible to perform multi-variate regression in Python using NumPy? The documentation here suggests that it is, but I cannot find any more details on the topic.

Regressing panel data in SAS

I am now looking at a panel dataset on which I have to regress. Since I only started my Phd this semester together with the econometrics courses I am still new to many statistic applications and ...

Mysql multivariable linear regression

I am trying to do a multivarible (9 variables) linear regression on data in my mysql 5.0 database (the result value field only has 2 possible values, 1 and 0). I ve done some searching and found I ...

scipy linregress function erroneous standard error return?

I have a weird situation with scipy.stats.linregress seems to be returning an incorrect standard error: from scipy import stats x = [5.05, 6.75, 3.21, 2.66] y = [1.65, 26.5, -5.93, 7.96] gradient, ...

How to do a linear regression into a BIRT report?

How to make a linear regression on the chart displayed into your BIRT report. I have x and y data... but I don t see any function on eclipse BIRT to generate the linear regression... Any idea ? Many ...

热门标签