r - R: PCA - 如何使用 svydesign 制作调查设计对象
问题描述
我是 R 中的主成分分析的新手。我目前正在使用我自己的数据通过 PCA,按照以下示例:Coreysparks 的 PCA
我被困在需要我创建调查设计对象的部分。这是我的代码:
options(survey.lonely.psu = "adjust")
scwb<-scwb[complete.cases(scwb),]
des<-svydesign(ids=~psu, strata=~ststr, weights=~cntywt, data=scwb , nest=T)
然后我收到以下消息 -
Error in eval(predvars, data, env) : object 'psu' not found
我尝试用 代替psu
,1
因为我很确定我正在使用简单随机抽样。但随后错误消息指出object 'ststr' not found
,我认为对于cntywt
. 我已经为此工作了几个小时,但我根本无法弄清楚(即使经过相当多的研究)如何正确填写此功能,以便我可以继续使用 PCA。
关于如何解决这个问题的任何建议?
编辑:这是我的数据示例:
IDN
Jobsat_1 Jobsat_2 Jobsat_3 Member_1 Member_2 Member_4 LingInt Belong_2 Belong_3 Grpor_14 Ethnic10 MEDIAb Trust_G1 Trust_G2
1 10 10 8 3 1 1 5 10 10 2 1 2 1 3
2 7 7 5 4 1 1 5 10 10 4 4 2 3 3
3 7 7 7 1 1 1 5 9 10 4 3 2 1 1
4 7 7 7 2 1 1 5 10 10 3 3 2 3 3
5 7 8 8 3 3 3 5 10 8 3 4 2 3 3
6 7 7 7 2 1 2 5 10 8 4 3 2 5 3
Grpor_3 Grpor_4 Grpor_12 Emp_1 Volas_10 Mstatus1 Child_1 Health_1 YRBIRTH Rgender Brthcoun YR_IMM Relig_2 Educ_R INCOM_14
1 1 5 2 3 15 0 0 2 31 1 1 100 3 4 73
2 7 6 9 2 15 1 5 1 40 2 1 100 7 8 105
3 5 5 7 1 10 1 3 3 60 1 1 100 4 3 40
4 8 8 8 3 4 1 4 2 63 1 1 100 2 3 30
5 5 4 8 2 20 1 0 2 37 2 1 100 3 8 60
6 7 7 10 2 20 1 1 2 37 2 1 100 6 8 73
Emp_1.1 pc1 pc2 pc3 pc4 pc5 pc6 pc7 pc8 pc9 pc10
1 3 1.9148465 4.9846483 -0.8072519 -3.3183158 -3.32593626 -0.8836492 0.4113892 1.26298570 -0.32539801 1.4829219
2 2 -0.8358479 -0.3853229 -2.4203323 0.2514915 -0.08298205 -0.8393284 0.2384652 -0.04452874 -0.76024480 3.0219680
3 1 0.5800140 1.3872784 -3.8136358 -1.4466660 0.49100339 1.0119573 0.3198218 -0.27307314 -1.46013793 -0.7989148
4 3 -1.0482772 0.4416652 -2.7239398 -2.0870089 -1.23500720 -1.6997003 0.2737917 0.76019756 -1.41174450 0.2476696
5 2 0.1772093 0.7945494 0.3299359 0.7466387 -0.37083214 -0.2998434 0.4494944 -0.04000732 -0.09798538 -0.1694823
6 2 -1.5970861 -0.3793862 -2.0577713 -1.2681369 0.02748217 -0.8220763 0.1409177 -0.15252729 -1.15142836 -0.2362450
pc11 pc12 pc13
1 -0.06980251 0.6393237 -0.66798274
2 -0.39774429 -0.1281088 -0.06633185
3 0.33557364 0.4008058 -1.13155741
4 0.07448897 -0.5383089 -0.02582100
5 -0.04507346 -0.1805617 1.42605349
6 -0.06659864 1.1336526 0.04854108
解决方案
推荐阅读
- docker - Docker 版本与命令的预期不同
- python - python OpenCV检测所有具有预定义值的像素
- trading - 我的 MQL4 订单发送正常,但没有任何反应,也没有发送订单?
- ms-project - 如何使用 VBA 从 excel 导入项目的开始和结束日期?
- python - 一致且可重现的轴间距
- android - DropdownButton 不更新颤振中的值
- animation - 组合多个 QML 行为
- c# - 在 foreach 的迭代中访问类的方法
- python - 对已分组的 Pandas 系列的索引执行操作
- firebase - E/RecyclerView:没有附加适配器;从实时数据库中获取数据时跳过布局