' in formula 'x' define table columns and are expected to be factors with meaningful labels.

问题描述 投票:0回答:1
The output also gives -9 as a value for the has_PCP nominal values, which I don't want either.

enter image description hereHere is where I got the code from (column of p values).

https:table1(~ age + obese + low_income + married + HSless + hosp_visits_2years + ER_2years + nights_hosp_2years | has_PCP, data=Oak, droplevels=F, render=rndr, render.strat=rndr.strat, overall=F)

我想用 "table1 "软件包制作一个表格,其中包含几个名义值和几个逻辑值,并与一个名义值相对应。我还想让每一列都包含一个p值。

这段代码。

给我这个警告:

警告信息: 在table1. formula(~age + obese + low_income + married + HSless + : Terms to the right of '/cran.r-project.orgwebpackagestable1vignettestable1-examples.html'右边的术语

r p-value chi-squared t-test
1个回答
0
投票

添加p值,使用 table1 同名软件包中的函数是一个黑客,根据你链接到的小插图中的代码,这个函数似乎不起作用。

如果你想换一种方法,可以试试 tableStack 包中的epiDisplay函数。

library(epiDisplay)  # for the function
library(MatchIt)     # for the lalonde data

data(lalonde)

labs <- c("No","Yes")
lalonde <- within(lalonde, {
                  treat    <- factor(treat, labels=c("Control", "Treatment"))
                  black    <- factor(black, labels=labs)
                  married  <- factor(married, labels=labs)
                  nodegree <- factor(nodegree, labels=labs)
})

attr(lalonde, "var.labels") <- c("Treatment","Age (yrs)","Education","Black","Hispanic","Married", 
                             "No high school diploma", "1974 Income", "1975 Income", "1978 Income")

这只是准备变量和值的标签。

下面的命令为变量的一个子集创建表格。您可以在屏幕上查看输出。

Table1 <- tableStack(vars=c(age, black, married, nodegree, re78), by=treat, dataFrame=lalonde, 
                     iqr=re78, name.test=FALSE)

Table1

或将其发送至文本文件。

write.csv(Table1, file="Table1.csv")

您可以在Excel中打开它,然后复制到Word中,并需要进行一些小的格式化。

enter image description here

测试是根据在下面指定的变量类别自动选择的。vars. 指定变量 iqr 强制函数显示这些变量的中位数和IQR,并进行行列和检验。所有其他在 vars 将显示均值和SD,并根据组数进行t.检验(方差汇总)或方差分析。对于因子,将执行chi-squared或Fisher's检验。不幸的是,如果任何变量的计数为零,该函数就会失败,这对你的许多变量来说都是如此(肥胖、低收入、已婚...)。所以它对于数据探索来说并不理想。

© www.soinside.com 2019 - 2024. All rights reserved.