简体   繁体   English

table1中的P值列-使用table1函数

[英]P-value column in table1 - using table1 function

NOTE - im referring to "table1" function, not "tableOne" 注–我指的是“ table1”函数,而不是“ tableOne”

As you might know table1 package summarizes the data into table by putting up some variable against all the others (like how many males vs females - smoked, got the drug, etc..) 您可能知道table1包通过将一些变量与所有其他变量放在一起来将数据汇总到表中(例如,男性与女性之间的人数-吸烟,吸毒等)。

Very good guidelines about the table1 function here. 关于table1功能的非常好的指导原则。

https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html

In lowest part of link site above you can see the writer making p-value column by using trick since the command is not built into table1. 在上面的链接站点的最下部,您可以看到编写者通过使用技巧在p值列中进行了编写,因为该命令未内置在table1中。 The thing is that its no problem with his code since he is only dealing with "male" and "female" (2 variables).. and im trying to do it with 4 variables. 问题是他的代码没有问题,因为他只处理“ male”和“ female”(2个变量)..我试图用4个变量来处理它。

Im fitting it so it can use my variables, im getting error and need help 我适合它,所以它可以使用我的变量,我遇到错误并需要帮助

ERROR 错误

"argument is not numeric or logical: returning NACalling var(x) on a factor x is deprecated and will become an error. Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") : missing value where TRUE/FALSE needed" “参数不是数字或逻辑的:不赞成在因子x上返回NACalling var(x),这将成为错误。请使用'all(duplicated(x)[-1L])'之类的东西来测试常数向量。Error在if(stderr <10 * .Machine $ double.eps * max(abs(mx),abs(my)))stop(“数据本质上是常数”)中:缺少值,需要TRUE / FALSE“

a <- c(0,13.3,14.0,14.7,15.8,999.0)

dat1$RDWquintiles<-cut(dat1$RDW_pre,a,include.lowest = TRUE)

z <- levels(dat1$RDWquintiles)
dat1$RDWquintiles <- factor(dat1$RDWquintiles,levels=c(z,factor("P-value")),labels=c("0,13.3","13.3,14","14,14.7","14.7,15.8","15.8,999","P-values" ))

dat1$RDWquintiles

table(dat1$RDWquintiles)


rndr <- function(x, name, ...) {
    if (length(x) == 0) {
        y <- dat1[[name]]
        s <- rep("", length(render.default(x=y, name=name, ...)))
        if (is.numeric(y)) {
            p <- t.test(y, dat1$RDWquintiles)$p.value
        } else {
            p <- chisq.test(table(y, droplevels(dat1$RDWquintiles)))$p.value
        }
        s[2] <- sub("<", "&lt;", format.pval(p, digits=3, eps=0.001))
        s
    } else {
        render.default(x=x, name=name, ... ,)
    }
}

rndr.strat <- function(label, n, ...) {
    ifelse(n==0, label, render.strat.default(label, n, ...))
}

table1(~ Age + Sex + LOS + Open + adm_PE |RDWquintiles,data=dat1, droplevels=F, render=rndr, render.strat=rndr.strat, overall=F)

You might need to check your data. 您可能需要检查数据。 I don't have your dataset so I can't reproduce your error. 我没有您的数据集,所以我无法重现您的错误。 The only issue I see with having 4 groups to compare instead of 2 is that you cannot use a T-test for continuous variables, you would need to choose an appropriate test like ANOVA or Kruskal-Wallis to derive the P-value (in general, the P-value depends on the test used; selecting an appropriate test is an important consideration, but outside the scope of the current question). 我看到的有4组而不是2组进行比较的唯一问题是,您不能对连续变量使用T检验,您需要选择ANOVA或Kruskal-Wallis等适当的检验来得出P值(通常,则P值取决于所使用的测试;选择适当的测试是重要的考虑因素,但不在当前问题的范围之内。

Here I have adapted the example from the vignette (I don't repeat the whole code, just the relevant changes): 在这里,我从小插图改编了该示例(我不重复整个代码,只重复相关更改):

lalonde$age.quartiles <- eqcut(lalonde$age, 4, varlabel="Age")
lalonde$age.quartiles <- factor(lalonde$age.quartiles,
    levels=c(levels(lalonde$age.quartiles), "P-value"))

rndr <- function(x, name, ...) {
    if (length(x) == 0) {
        y <- lalonde[[name]]
        s <- rep("", length(render.default(x=y, name=name, ...)))
        if (is.numeric(y)) {
            p <- kruskal.test(y ~ lalonde$age.quartiles)$p.value
        } else {
            p <- chisq.test(table(y, droplevels(lalonde$age.quartiles)))$p.value
        }
        s[2] <- sub("<", "&lt;", format.pval(p, digits=3, eps=0.001))
        s
    } else {
        render.default(x=x, name=name, ...)
    }
}

table1(~ black + hispan + married + nodegree + re74 + re75 + re78 | age.quartiles,
    data=lalonde, droplevels=F, render=rndr, render.strat=rndr.strat, overall=F)

Note: this is not part of the original question, but I thought I would mention that the table1 package contains the function eqcut which can be conveniently used to create equal-sized groups such as tertiles, quartiles, etc. 注意:这不是原始问题的一部分,但是我想我要提到table1软件包包含eqcut函数,该函数可以方便地用于创建相等大小的组,例如三分位数,四分位数等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM