gpt4 book ai didi

Creating an epidemiological prevalence table in R using dataset(使用数据集在R中创建流行病学流行病表)

转载 作者:bug小助手 更新时间:2023-10-24 22:22:55 24 4
gpt4 key购买 nike



I have previously created a prevalence table in SAS but I am trying to replicate it in R. I have attached description and image of target table below.

我之前已经在SAS中创建了一个流行率表,但我正在尝试在R中复制它。我已在下面附上了目标表的描述和图像。


I having trouble creating a simple table the shows prevalence by age and sex. I have tried using various methods including the gt_summary package with the following code but no luck.

我在创建一个简单的表格时遇到了困难,表格中显示了按年龄和性别划分的患病率。我尝试过使用各种方法,包括带有以下代码的GT_SUMMARY包,但没有成功。


#prevalence of Chagas by age and sex
df_linked6 %>%
select(Age_interval, Sex, Confirmatory_results) %>%
tbl_summary(
by = Sex,
label = list(Age_interval ~ "Age (yrs)”,
Confirmitory_results ~ “Confirmed"),
percent = "row",
statistic = list(Age_interval ~ "{n}/{N} ({p}%)"),)

I have created the table in SAS before but cant seem to replicate it in R. My variables for column 1 is Age_interval for 10 year levels. The next column Id like is a an overall summary of the prevalence, and the following two columns correspond to my Sex variable. For each cell I'd like the prevalence of my disease which can be calculated by my Confirmatory_results variable.

我以前在SAS中创建了表,但似乎不能在R中复制它。我第1列的变量是10年水平的Age_Interval。下一列ID Like是流行率的总体摘要,以下两列对应于My Sex变量。对于每个单元格,我想知道我的疾病患病率,这可以通过我的CONFIRITIAL_RESULTS变量来计算。


I have attached my target table. Any help/suggestions would greatly help! Thanks.

我已经附上了我的目标桌子。任何帮助/建议都会有很大帮助!谢谢。


enter image description here


更多回答

Rather than tbl_summary(), I think you'll have better luck with gsummary::tbl_cross(). If you update your post with a minimal reproducible example, aka a reprex, the community could assist further. reprex.tidyverse.org

我认为使用gsum::tbl_cross()会比使用tbl_sum()更幸运。如果你更新你的帖子,用一个最小的可重现的例子,也就是Reprex,社区可以提供进一步的帮助。Reprex.tidyverse.org

Welcome to SO, jhar123! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (good start here, please be explicit about non-base packages), sample representative data (perhaps via dput(head(x)) or building data programmatically (e.g., data.frame(...)), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: stackoverflow.com/q/5963269, minimal reproducible example, and stackoverflow.com/tags/r/info.

欢迎来到So,Jhar123!关于SO的问题(特别是在R中),如果它们是可重现的和独立的,就会做得更好。我的意思是,包括尝试的代码(这里是良好的开端,请明确说明非基包)、样本代表性数据(可能是通过dput(head(X)或以编程方式构建数据(例如,data.Frame(...),可能是随机的),可能是实际输出(带有逐字错误/警告)与预期输出。参考文献:STACKOVERFLO.com/Q/5963269,可重现的最小示例,和STACKOVERFLO.com/TAG/r/INFO。

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com