pewresearch / pewmethods Goto Github PK
View Code? Open in Web Editor NEWPew Research Center Methods team R package of miscellaneous functions
License: MIT License
Pew Research Center Methods team R package of miscellaneous functions
License: MIT License
Are there any plans to make the package available on CRAN?
rake_survey
throws the error mentioned in the title. Simple reproducible example below (this follows https://medium.com/pew-research-center-decoded/weighting-survey-data-with-the-pewmethods-r-package-d040afb0d2c2):
library(pewmethods)
fullpopulation <- data.frame(runif(1000), as.factor(ifelse(runif(1000) > 0.5, 'A', 'B')))
names(fullpopulation) <- c('x','weighting_variable')
my_skewed_sample <- data.frame(runif(100), as.factor(ifelse(runif(1000) > 0.9, 'A', 'B')))
names(my_skewed_sample) <- c('x','weighting_variable')
targets <- create_raking_targets(
fullpopulation,
vars = c('weighting_variable'),
wt = 1
)
rake_survey(my_skewed_sample, pop_margins = targets)
I get the error: Error: All elements of
fs must be factors
I managed to trace the error to unify_margins
function called by rake_factors()
. A simple workaround was to comment out the line where unify_margins
is called. This works fine if factor levels in fullpopulation$weighting_variable and my_skewed_sample$weighting_variable match.
For reference, here is my R version:
> R.Version()
$platform
[1] "x86_64-apple-darwin15.6.0"
$arch
[1] "x86_64"
$os
[1] "darwin15.6.0"
$system
[1] "x86_64, darwin15.6.0"
$status
[1] ""
$major
[1] "3"
$minor
[1] "5.1"
$year
[1] "2018"
$month
[1] "07"
$day
[1] "02"
$`svn rev`
[1] "74947"
$language
[1] "R"
$version.string
[1] "R version 3.5.1 (2018-07-02)"
$nickname
[1] "Feather Spray"
And here's my system info:
> Sys.info()
sysname
"Darwin"
release
"18.7.0"
version
"Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64"
nodename
"MacBook-Air.local"
machine
"x86_64"
Tidyverse functions generally take the data argument first, making it easier to use the %>%
operator. For example:
dec13_excerpt <- dec13_excerpt %>% mutate(fake_weight = coalesce(llweight, cellweight))
get_totals("q1", dec13_excerpt, wt = c("weight", "fake_weight"), include_unw = TRUE)
becomes:
dec13_excerpt <- dec13_excerpt %>%
mutate(fake_weight = coalesce(llweight, cellweight)) %>%
get_totals("q1", wt = c("weight", "fake_weight"), include_unw = TRUE)
Happy to submit a PR if you all are interested. This change could be relevant to other functions as well, I haven't checked.
Basic issue I realize, but I can't get the package to install. I currently have R version 3.6.3. I ran the following code:
install.packages(“devtools”)
install_github(“pewresearch/pewmethods”, build_vignette = TRUE)
I got the following error:
Error: Failed to install 'pewmethods' from GitHub:
(converted from warning) unable to access index for repository https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6:
cannot open URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/PACKAGES'
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.