Giter VIP home page Giter VIP logo

pewmethods's People

Contributors

labsdeployuser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pewmethods's Issues

rake_survey "Error: All elements of `fs` must be factors"

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"

make df the first argument in get_totals to work more seamlessly with dplyr

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.

Installing "pewmethods" package

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.