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, 0, 1, 1, 1, 1, 1, 0, 0, 
    1, 0, 1, 1), UH6407a = c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
    1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 
    1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 
    1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1), weight = c(405.002592353822, 
    479.360356183825, 526.548105855472, 810.005184707644, 312.321528531308, 
    930.961115757095, 567.383058387095, 475.323944260643, 1226.91439266118, 
    517.086839792615, 1200.2669656949, 810.005184707644, 656.723784884795, 
    605.370463928298, 668.467435759576, 558.112457492436, 793.751055244424, 
    479.360356183825, 1226.91439266118, 1606.54816212786, 1657.48609449633, 
    300.803580980276, 605.370463928298, 1140.55078447979, 669.102760422943, 
    810.005184707644, 1657.48609449633, 305.569853371963, 2994.30343152033, 
    762.922030382216, 479.360356183825, 1147.36030437824, 668.467435759576, 
    517.086839792615, 479.360356183825, 399.141865860217, 656.723784884795, 
    913.364738988386, 312.321528531308, 569.10576379231, 775.630259688922, 
    1207.22952429547, 1053.09621171094, 1140.55078447979, 314.857225320909, 
    668.467435759576, 2416.57081451012, 573.680152189121, 396.875527622212, 
    605.370463928298, 1036.3159447043, 3088.62283807823, 569.10576379231, 
    1140.55078447979, 2416.57081451012, 1147.36030437824, 762.922030382216, 
    702.064141140629, 351.032070570315, 629.714450641817, 517.086839792615, 
    1996.20228768022, 828.743047248167, 475.323944260643, 920.185794495882, 
    793.751055244424, 796.08788273764, 1197.42559758065, 405.002592353822, 
    418.584343119327, 300.803580980276, 654.76828203733, 2740.09421696516, 
    351.032070570315, 1069.6202614693, 2094.91447516374, 399.141865860217, 
    654.76828203733, 1003.65414063441, 573.680152189121, 851.074587580641, 
    913.364738988386, 762.922030382216, 1034.17367958523, 573.680152189121, 
    479.360356183825, 3208.8607844079, 654.76828203733, 908.055695892447, 
    328.361892442398, 1036.3159447043, 702.064141140629, 613.457196330588, 
    601.607161960551, 567.383058387095, 479.360356183825, 306.261087672466, 
    920.185794495882, 654.76828203733, 828.743047248167)), .Names = c("UH6401", 
"UH6402", "UH6403", "UH6404", "UH6409", "UH6410", "UH6411", "UH6412", 
"UH6503", "UH66", "UH68", "UH6501a", "UH6405a", "UH6407a", "weight"
), row.names = c(NA, 100L), class = "data.frame")

在社会科学中,我们通常有一个权重变量,通过该变量的因子对案例(行)进行加权,以校正样本以适应例如按年龄类别的人口。如果一行的权重变量为“1.6”,则意味着该行需要观察 1.6 次才能拟合基础总体。

在 SPSS 中,我会编写

WEIGHT BY weight. 

该命令之后的所有程序都会相应地对数据进行加权。

在 RI 中,可以使用命令来做到这一点

xtabs(weight ~ UH6401, data=df)

但是如果我想做 SVD 或 PCA 分析怎么办?这里没有像 xtabs 中那样对数据进行加权的功能。

所以问题是,R 中是否有一种像 SPSS 中那样对数据进行加权的方法? 整数点很容易,使用因子“2”我们只需将线加倍,但是所有因子都是小数怎么办?


更新:

SVD 或 PCA 只是一个例子!采取任何其他统计程序。 在社会科学中,样本从来都不是完美的,但要对样本数据进行统计分析,样本需要代表基本总体,但样本大多不能代表基本总体。所以我们尝试用权重来弥补这个不足,所以样本代表了基本人群!

Given is the following data frame:

structure(list(UH6401 = c(1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 
1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 
0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0,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 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1), weight = c(405.002592353822, 
    479.360356183825, 526.548105855472, 810.005184707644, 312.321528531308, 
    930.961115757095, 567.383058387095, 475.323944260643, 1226.91439266118, 
    517.086839792615, 1200.2669656949, 810.005184707644, 656.723784884795, 
    605.370463928298, 668.467435759576, 558.112457492436, 793.751055244424, 
    479.360356183825, 1226.91439266118, 1606.54816212786, 1657.48609449633, 
    300.803580980276, 605.370463928298, 1140.55078447979, 669.102760422943, 
    810.005184707644, 1657.48609449633, 305.569853371963, 2994.30343152033, 
    762.922030382216, 479.360356183825, 1147.36030437824, 668.467435759576, 
    517.086839792615, 479.360356183825, 399.141865860217, 656.723784884795, 
    913.364738988386, 312.321528531308, 569.10576379231, 775.630259688922, 
    1207.22952429547, 1053.09621171094, 1140.55078447979, 314.857225320909, 
    668.467435759576, 2416.57081451012, 573.680152189121, 396.875527622212, 
    605.370463928298, 1036.3159447043, 3088.62283807823, 569.10576379231, 
    1140.55078447979, 2416.57081451012, 1147.36030437824, 762.922030382216, 
    702.064141140629, 351.032070570315, 629.714450641817, 517.086839792615, 
    1996.20228768022, 828.743047248167, 475.323944260643, 920.185794495882, 
    793.751055244424, 796.08788273764, 1197.42559758065, 405.002592353822, 
    418.584343119327, 300.803580980276, 654.76828203733, 2740.09421696516, 
    351.032070570315, 1069.6202614693, 2094.91447516374, 399.141865860217, 
    654.76828203733, 1003.65414063441, 573.680152189121, 851.074587580641, 
    913.364738988386, 762.922030382216, 1034.17367958523, 573.680152189121, 
    479.360356183825, 3208.8607844079, 654.76828203733, 908.055695892447, 
    328.361892442398, 1036.3159447043, 702.064141140629, 613.457196330588, 
    601.607161960551, 567.383058387095, 479.360356183825, 306.261087672466, 
    920.185794495882, 654.76828203733, 828.743047248167)), .Names = c("UH6401", 
"UH6402", "UH6403", "UH6404", "UH6409", "UH6410", "UH6411", "UH6412", 
"UH6503", "UH66", "UH68", "UH6501a", "UH6405a", "UH6407a", "weight"
), row.names = c(NA, 100L), class = "data.frame")

In social science we often have a weight variable to weight a case (row) by the factor of that variable to correct the sample to fit e.g. the population by age classes. If the weight variable of a row is "1.6" it means that this row need do be observed 1.6 times to fit the basis population.

In SPSS I would write

WEIGHT BY weight. 

and all procedures after that command will weight the data accordingly.

In R I can do that with stabs with the command

xtabs(weight ~ UH6401, data=df)

But what if I want to do a SVD or PCA analysis? Here there is no function to weight data like it is in xtabs.

So the question is, is there a method to weight data in R like it is possible in SPSS?
The point with whole numbers would be easy, with the factor "2" we would just double the line, but what is with all the factors that are decimal?


UPDATE:

The SVD or PCA was just an example! Take any other statistical procedure.
In social science the samples are never perfect, but to do an statistical analysis with sample data, the sample needs to represent the basic population, but a sample mostly doesn't. So we try to fix that deficit with weights, so the sample represent the basic population!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

江城子 2024-12-06 05:29:00

首先,对这些数据进行 PCA 没有意义。其次,SPSS不进行PCA,而是进行因子分析,这是另一回事。我知道他们称之为 PCA,但事实并非如此。

SPSS 中的 WEIGHT BY 无非是一个复制权重,与使用 rep() 重复案例进行分析完全一样:完全疯狂。链接到您的示例:在 SPSS 中,因子(用于所谓的 PCA)不采用分数权重。

如果您想执行加权过程,唯一明智的方法是使用正确的方法/函数/包。在统计学中,不存在一刀切的重量程序,这与 SPSS 想让您相信的相反。

在您的示例中:R中的加权PCA包含在 FactoMineRaroma.light。但我强烈建议您也看看 vegan 包,因为它包含您所描述的数据的许多更有用的排序方法。

First of all, doing PCA on this data doesn't make sense. Second, SPSS does not perform PCA but factor analysis, which is something else. I know they call it PCA, but it isn't.

The WEIGHT BY in SPSS is nothing more than a replication weight, and is exactly the same as doing your analysis by repeating your cases using rep(): complete madness. To link to your example: In SPSS, FACTOR (which is used for the socalled PCA) does not take fractional weights.

If you want to perform weighted procedures, the only sensible way of doing that is using the correct method/function/package for that. In statistics, there is no one-size-fits-all weight procedure, contrary to what SPSS likes to make you believe.

In your example : weighted PCA in R is contained in FactoMineR and aroma.light. But I strongly suggest you take also a look at the vegan package, as that contains a lot more useful ordination methods for the data you're describing.

月朦胧 2024-12-06 05:29:00

您可能需要熟悉 R. Baron 的 RSiteSearch 和 Rseek 搜索引擎:
这是 Baron 网站上“加权 PCA”的首批点击之一:

http://finzi.psych.upenn.edu/R/library/aroma.light/html/wpca.matrix.html

评论中的澄清Joris Meys 的回应是,答案通常是,人们需要明确自己想要的是样本权重,而不是其他类型的权重。回归加权是通过 survey 包完成的。拉姆利关于调查方法的书区分了三种类型的权重。 (lm 函数中的“权重”是方差权重,而不是样本权重。)

注意:PCA 和因子分析(实验)均包含在调查包中。因此,也许多米尼克的问题要求在回归方法中采用统一的加权方法有一个“答案”。

You probably need to get acquainted with the search engines for R. Baron's RSiteSearch and Rseek:
This is one of the first hits on "weighted PCA" at Baron's site:

http://finzi.psych.upenn.edu/R/library/aroma.light/html/wpca.matrix.html

With the clarification in the comment to Joris Meys response, the answer is often that one needs to be clear that one is desires sample weights versus other types of weighting. Regression weighting is done with the survey package. Lumley's book on survey methods distinguishes among three types of weights. (The "weights" in the lm function are variance weights, NOT sample weights.)

Note: Both PCA and factor analysis (experimental) are included in the survey package. So maybe Dominick's question requestiong a unified approach to weighting in regression methods has a single "answer".

秋千易 2024-12-06 05:29:00

我不确定这是否适合您。请参阅 R 包权重

I am not sure if this would suite you. See the R package weights.

白衬杉格子梦 2024-12-06 05:29:00

我刚刚在 R-Bloggers 中找到了帖子< /a> 引入了 svydesign() 函数。据我所知,“调查”包中的这个功能类似于 SPSS 功能,允许您创建加权数据以用于进一步分析。我发现它比使用多个包中的不同函数来进行多变量分析更有用。

@djhurio 注意:使用代码答案会更好。这似乎与我的答案有点重复,该答案指向包含“svydesign”的 survey 包。四年后,所引用的网页仍然存在,但情况可能并非总是如此。

I have just found a Post in R-Bloggers which introduces a svydesign() function. As far as I know, this function from the 'survey' package is like SPSS function, allowing you to create a weighted data to use in further analysis. I find it more useful than using different functions from several packages in order to do multivariable analysis.

Note to @djhurio: The answer would have been better with code. It does seem a bit duplicative of my answer which pointed to the survey package that contains 'svydesign'. The cited webpage is still there 4 years later, but that might not always be the case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文