-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weighted frequencies #136
Comments
If you give me an example with real data that I can replicate, and possibly the survey package command you want to emulate, then I will almost certainly find a solution for you.
…On Sun, Sep 13, 2020, at 08:22, andresimi wrote:
Hi, is it possible to apply a weight to have weighted frequencies in
modelsummary?
Or to work with survey data from survey package?
thanx
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#136>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHQ7MLREA5R5ROVHBL4NWTSFS2PLANCNFSM4RKUGR7Q>.
--
Vincent Arel-Bundock
Professeur agrégé / Associate professor
http://arelbundock.com
Université de Montréal, Science politique
3150 rue Jean-Brillant, Pav. Lionel-Groulx, C-4020
Montréal, Québec, Canada, H3T 1N8
|
Thanx a lot. The table I am trying to reproduce is something like this one: And the code I was working until now is the following:
|
The easiest way to do this would probably be to divide your weights by the sum of weights in the subgroup which you want to use as margins (i.e., in the subgroup where the sum of frequencies should equal 100%). Then, you just take the sum of these new weights. Does something like this work for you? library(tidyverse)
library(modelsummary)
data <- readRDS("table_example.rds") %>%
group_by(redcap_event_name, age_group, selection) %>%
mutate(weights = weights / sum(weights) * 100)
f <- Factor(dcany) + Factor(dcanyanx) + 1 ~
sum * weights * redcap_event_name * age_group * selection * DropEmpty()
datasummary(f, data) |
Hi, is it possible to apply a weight to have weighted frequencies in modelsummary?
Or to work with survey data from survey package?
thanx
The text was updated successfully, but these errors were encountered: