[R] How do I get a weighted frequency table?

Luca Meyer lucam1968 at gmail.com
Mon Aug 29 19:37:46 CEST 2011


Hi David,

Unfortunately I need to use the "should have been" frequencies if the sample corresponded perfectly in terms of some "reference" variables to the population. 

That is, if in my sample I observe V1_R1=10%, V1_R2=50%, V3_R3=40% while the same known population distribution is V1_R1=20%, V1_R2=30%, V3_R3=50% then I would like to see what V2*V3, V2*V4, ... , V2* VN, V3*V4, ... ,VN-1 * VN would have been had the sample perfectly reflect the population in terms of V1.

I hope that clarifies what I am trying to achieve...

Thanks,
Luca

Il giorno 29/ago/2011, alle ore 16.29, David L Carlson ha scritto:

> If you are talking about weights that are the frequencies in each cell, you
> can use xtabs():
> 
> df <- data.frame(Var1=c("Absent", "Present", "Absent", "Present"), 
>     Var2=c("Absent", "Absent", "Present", "Present"), Freq=c(17, 6, 3, 12))
> df
> xtabs(Freq~Var1+Var2, data=df)
> 
> ----------------------------------------------
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
> 
> 
> 
> -----Original Message-----
> From: r-help-bounces a r-project.org [mailto:r-help-bounces a r-project.org] On
> Behalf Of Leandro Marino
> Sent: Sunday, August 28, 2011 12:15 PM
> To: Luca Meyer
> Cc: r-help a r-project.org
> Subject: Re: [R] How do I get a weighted frequency table?
> 
> *Luca,
> *
> 
> 
> you may use survey package. You have to declare the design with design
> function and than you can you svytotal, svyby, svymean functions to do your
> tabulations.
> 
> Regards,
> Leandro
> 
> 
> 
> Atenciosamente,
> Leandro Marino
> http://www.leandromarino.com.br (Fotsgrafo)
> http://est.leandromarino.com.br/Blog (Estatmstico)
> Cel.: + 55 21 9845-7707
> Cel.: + 55 21 8777-7907
> 
> 
> 
> 2011/8/28 Luca Meyer <lucam1968 a gmail.com>
> 
>> Hello,
>> 
>> I have to run a set of crosstabulations to which I need to apply some 
>> weights. I am currently doing an unweighted version of such crosstabs 
>> using table(x,y).
>> 
>> I am used with SPSS to create a weighting variable and to use WEIGHT 
>> BY VAR before running the CTABLES, is there a similar procedure in R?
>> 
>> Thanks,
>> Luca
>> 
>> Mr. Luca Meyer
>> www.lucameyer.com
>> R version 2.13.1 (2011-07-08)
>> Mac OS X 10.6.8
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>       [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help a r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 	[[alternative HTML version deleted]]
> 
> 



More information about the R-help mailing list