R 如何从“svyby”中获取可读表?
我想以一个三维表格结束,该表格显示每个变量的比例(即百分比),由两个二分法变量分割。这就是我所写的代码,我认为它将生成我所寻找的东西的简化版本R 如何从“svyby”中获取可读表?,r,survey,R,Survey,我想以一个三维表格结束,该表格显示每个变量的比例(即百分比),由两个二分法变量分割。这就是我所写的代码,我认为它将生成我所寻找的东西的简化版本 > Testdesign <- svydesign(id = ~V021, strata= ~V022, weights = ~SAMPW, data= testydf) > Tableone <- svyby( ~ V104 + V025 , ~ V013 + V502 , Testdesign , svyciprop, v
> Testdesign <- svydesign(id = ~V021, strata= ~V022, weights = ~SAMPW, data= testydf)
> Tableone <- svyby( ~ V104 + V025 , ~ V013 + V502 , Testdesign , svyciprop,
vartype="ci", method="beta", na.rm = TRUE
我可以尝试使用交叉表
功能,但我不确定如何将其与复杂的调查数据集成(因此,首先选择调查
)
stargazer
看起来很有希望,但它似乎没有正确读取svyby
输出,因此ftable
似乎仍然是必要的
编辑:这里有一个子集可以与上面的代码一起使用,很抱歉这段文字太糟糕了
> testydf <- structure(list(V001 = c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3,
4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7), V002 = c(124,
166, 178, 178, 216, 2, 2, 214, 34, 149, 167, 221, 248, 62, 72,
196, 6, 14, 51, 101, 188, 221, 129, 167, 186, 14, 18, 26, 97,
111), V003 = c(2, 2, 2, 3, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2,
2, 1, 2, 2, 2, 2, 6, 6, 3, 2, 1, 2, 2, 3), V004 = c(1, 1, 1,
1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6,
6, 7, 7, 7, 7, 7), V005 = c(118748, 118748, 118748, 118748, 118748,
1258174, 1258174, 1258174, 1931847, 1931847, 1931847, 1931847,
1931847, 47672, 47672, 47672, 911631, 911631, 911631, 911631,
911631, 911631, 2005349, 2005349, 2005349, 1060772, 1060772,
1060772, 1060772, 1060772), V013 = c(3, 3, 3, 1, 3, 5, 1, 5,
3, 2, 7, 2, 4, 2, 2, 7, 5, 3, 2, 5, 2, 4, 1, 1, 2, 2, 4, 7, 3,
1), V106 = c(2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 2, 1, 1,
0, 1, 2, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1), SEX = c(1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1), V502 = c(0, 1, 1, 0, 1, 2, 0, 1, 0, 1, 1, 1,
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 1, 1, 1, 1, 0), V025 = c(1,
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2), V190A = c(4, 5, 1, 1, 2, 2, 2, 1, 1,
4, 4, 2, 1, 5, 5, 3, 1, 1, 1, 1, 1, 5, 2, 4, 2, 2, 2, 2, 2, 3
), V130 = c(2, 2, 4, 4, 6, 5, 5, 1, 6, 6, 3, 2, 6, 3, 5, 3, 1,
1, 1, 1, 1, 1, 5, 5, 6, 5, 5, 2, 2, 2), V131 = c(8, 1, 1, 1,
1, 1, 1, 1, 5, 5, 5, 1, 5, 10, 2, 4, 1, 1, 1, 1, 1, 1, 2, 1,
5, 8, 8, 8, 8, 8), V732 = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), V836 = c(1,
1, 1, 0, 1, 1, 1, 1, 1,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 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), V791B = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), HIV02 = c(6918, 6928, 6882, 6883, 6919, 9523, 9521, 10340,
446, 441, 445, 437, 436, 14071, 14065, 14066, 11443, 12111, 11328,
11395, 11644, 11309, 14547, 14626, 15067, 12464, 12466, 12459,
12462, 12468), HIV03 = structure(c(0, NA, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
), labels = structure(c(0, 1, 2, 3, 4, 5, 6, 7, 9), .Names = c("HIV negative",
"HIV positive", "HIV2 positive", "HIV1 & HIV2 positive", "ERROR : V-, W+, M+",
"ERROR : V-, W+, M-", "ERROR : V-, W-, M+", "Indeterminate",
"Inconclusive")), class = "labelled"), HIV05 = c(109959, 109959,
109959, 109959, 109959, 1212890, 1212890, 1212890, 1856921, 1856921,
1856921, 1856921, 1856921, 45717, 45717, 45717, 864793, 864793,
864793, 864793, 864793, 864793, 1974222, 1974222, 1974222, 1066907,
1066907, 1066907, 1066907, 1066907), HIV06 = structure(c(0, 1,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0), labels = structure(c(0, 1), .Names = c("Negative",
"Positive")), class = "labelled"), V104 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), TRANSEX = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), HIVKNOW = c(3,
2, 2, 2, 4, 7, 7, 4, 5, 4, 7, 4, 5, 4, 3, 4, 3, 6, 4, 2, 3, 3,
3, 4, 5, 5, 5, 4, 6, 4), HIVKCAT = c(1, 0, 0, 0, 1, 2, 2, 1,
2, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 0, 1, 1, 1, 1, 2, 2, 2, 1, 2,
1), V021 = c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
5, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7), V022 = c(18, 18, 18,
18, 18, 13, 13, 13, 33, 33, 33, 33, 33, 11, 11, 11, 25, 25, 25,
25, 25, 25, 9, 9, 9, 27, 27, 27, 27, 27), V023 = c(18, 18, 18,
18, 18, 13, 13, 13, 33, 33, 33, 33, 33, 11, 11, 11, 25, 25, 25,
25, 25, 25, 9, 9, 9, 27, 27, 27, 27, 27), V024 = c(2, 2, 2, 2,
2, 2, 2, 2, 3, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1,
2, 2, 2, 2, 2), SAMPW = c(0.109959, 0.109959, 0.109959, 0.109959,
0.109959, 1.21289, 1.21289, 1.21289, 1.856921, 1.856921, 1.856921,
1.856921, 1.856921, 0.045717, 0.045717, 0.045717, 0.864793, 0.864793,
0.864793, 0.864793, 0.864793, 0.864793, 1.974222, 1.974222, 1.974222,
1.066907, 1.066907, 1.066907, 1.066907, 1.066907)), .Names = c("V001",
"V002", "V003", "V004", "V005", "V013", "V106", "SEX", "V502",
"V025", "V190A", "V130", "V131", "V732", "V836", "V754CP", "V754DP",
"V754JP", "V754WP", "V756", "V823", "V824", "V761", "V525", "V732.1",
"V791", "V791B", "HIV02", "HIV03", "HIV05", "HIV06", "V104",
"TRANSEX", "HIVKNOW", "HIVKCAT", "V021", "V022", "V023", "V024",
"SAMPW"), row.names = c("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"
), class = "data.frame")
>testydf?svyciprop
状态
公式模型指定单个二进制变量的公式
设置
也可以正确地断开
svyby( ~ I( api99 > 500 ) + I( api00 > 500 ) , ~ sch.wide , dclus1, svyciprop)
您好,请修改您的问题,以包含一个最小的可复制示例<代码>?svyby
有示例,thanks@AnthonyDamico编辑是否构成可接受的可复制示例?-谢谢你我还不清楚你在问什么V104
为全零,您只需将其添加到V025
。如果您使用从?svyciprop
或?svyby
底部示例中提取的数据集,svyby
代码似乎运行良好,只是ftable
无法加载输出,我想知道为什么会这样。我认为这是我通过svyby
提供的内容的问题。从我所看到的一切来看,这似乎是通过两个其他变量得到每个变量(重量和设计调整)总体百分比的一个大表格的正确方法。我完全偏离了基准吗?当你说“正确断开”时,你的意思是“按预期抛出错误?”我在eval(family$initialize)中得到错误:y值必须为0是svyciprop
正在添加这些列,因此有时是两列。我不知道问题出在哪里,而且似乎我还没有专业知识/词汇来真正与其他人沟通我的问题出在哪里,所以我认为我需要走另一条路。谢谢你抽出时间!对于asdfree:)~V104+V025
是不允许的。与其他一些library(survey)
函数不同,svyciprop()
的第一个参数只需要一列。您希望这两个列分别使用svyciprop()
进行计算,但函数在通过svyciprop()
发送它们的总和之前添加(V104+V025)
,这在某些情况下会导致超出允许的[0,1]
范围
library(survey)
data(api)
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=apiclus1)
svyciprop( ~ I( api99 > 500 ) + I( api00 > 500 ) , dclus1 )
svyby( ~ I( api99 > 500 ) + I( api00 > 500 ) , ~ sch.wide , dclus1, svyciprop)