Ask Your Question
1

How can we use the `qwraps2` function to analyze data that includes nested groups?

asked 2023-06-12 09:00:58 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-12 09:03:02 +0000

nofretete gravatar image

To use the qwraps2 function to analyze data that includes nested groups, you can use the :: operator to specify the levels of the groups, and then use the by argument to group and summarize the data at each level. For example:

library(qwraps2)

# Example data with nested groups
data <- data.frame(
  region = c(rep("North", 6), rep("South", 6)),
  state = c(rep("NY", 3), rep("PA", 3), rep("TX", 3), rep("FL", 3)),
  sales = c(100, 150, 200, 75, 125, 175, 250, 300, 350, 225, 275, 325)
)

# Create a qwraps2 table with nested grouping by region and state
table1 <- qwraps2::summary_table(
  data = data,
  vars = c(sales),
  by = list(region::state),
  treatment = NULL,
  statistic = "mean_sd_n",
  missing = TRUE,
  digits = 2,
  report = TRUE
)

table1

This will create a summary table with mean, standard deviation, and sample size for sales at each level of the nested groups (e.g., mean sales for North NY, South PA, etc.).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-12 09:00:58 +0000

Seen: 12 times

Last updated: Jun 12 '23