Help everyone. I am currently trying to analyse a complex survey dataset, and I need to create a survey object in order to carry out weighted statistics. I am trying to use the srvyr package since it is easier to subsequently make plots with ggplot, but I am facing an error which I don't really know how to solve. Below Is my code:
if (!require(c("devtools","srvyr","tidyr","xtable","survey","readr","dplyr","plyr","ggplot2","readxl","tidyverse","svyPVpack","furrr","ggthemes","wesanderson"))) install.packages(c("devtools","srvyr","tidyr","xtable","survey","readr","dplyr","plyr","ggplot2","readxl","tidyverse","svyPVpack","furrr","ggthemes","wesanderson"))
library(c("devtools","srvyr","tidyr","xtable","survey","readr","dplyr","plyr","ggplot2","readxl","tidyverse","svyPVpack","furrr","ggthemes","wesanderson"))
packages <- c("devtools","srvyr","tidyr","xtable","survey","readr","dplyr","plyr","ggplot2","readxl","tidyverse","svyPVpack","furrr","ggthemes","wesanderson")
lapply(packages, library, character.only = TRUE)
setwd("~/Documents/Tesi/RECS/2015")
recs2015_public_v4 <- read_excel("recs2015_public_v4.xlsx")
recs=as.data.frame(recs2015_public_v4)
rm(recs2015_public_v4)
recs_design1=recs %>%
as_survey_rep(type="Fay",rho=0.5,repweights=starts_with("brrwt"), weights=nweight,combined.weights=FALSE)
p1<- recs_design1 %>%
group_by(hhsex) %>%
summarise(race = survey_mean(householder_race, na.rm=TRUE))
Error: Survey context not set
Call rlang::last_error()
to see a backtrace.
Could you please give me an hint on how to solve this problem? Thanks you all!