Giter Site home page Giter Site logo

Comments (11)

wmay avatar wmay commented on June 20, 2024

This seems to suggest something is wrong with the legislator ID values. Could some of them be NA? If you can find the specific commit where it breaks, that would definitely be helpful.

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

No, that isn't really possible. I have however made another very strange observation: If I restart the interactive R after the calculation fails (while saving my workspace) and then retry the same dwnominate call again, then it works. This is all very mysterious...

from dwnominate.

wmay avatar wmay commented on June 20, 2024

I'm pretty baffled by that, so I need more info to figure this out. What was the old version you tried? If you can make a reproducible example-- maybe you can make the error occur with only a small subset of your data-- that would be really helpful.

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

Actually it seems like I have the same problem with older versions of dwnominate. So far the only workaround I have found is to restart R, which seems very weird.

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

OK, I will try to narrow the problem down. Just in case you have any more ideas, I read my data into R from a relational database and then create the rollcall objects like this for the sessions:

l <- list()
for (i in unique(v$Session)) {
  session_v <- filter(v, Session == i)
  # Wide Form
  session_v_pivot <- session_v %>%
    mutate(ID = paste0(LastName, " (", ParlGroupAbbreviation, "/", CantonAbbreviation, ")" )) %>% 
    select(ID, PersonNumber, ParlGroupAbbreviation, party, IdVote, Decision) %>% 
    mutate(Decision_new = case_when(
      Decision == 1 ~ 1,
      Decision == 2 ~ 6,
      !Decision %in% c(1, 2) ~ 9
      )
    ) %>%
    select(-Decision) %>% 
    pivot_wider(names_from = IdVote, values_from = Decision_new)
  
  # Generate rcObject
  l[[length(l) + 1]] <- rollcall(
    data = session_v_pivot %>% select(-(1:4)),
    yea = c(1),
    nay = c(6),
    missing = c(9),
    notInLegis = NA,
    legis.names = session_v_pivot$ID,
    vote.names = names(session_v_pivot %>% select(-(1:4))),
    legis.data = session_v_pivot %>% select(1:4),
  )
}

res <- dwnominate::dwnominate(l)

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

I have attached my test data here: test.zip

To test:

  1. Unzip file containing test.rds.
  2. Start interactive R and run following commands:
library(pscl)
library(dplyr)
library(tidyr)
library(wnominate)
  1. Load test.rds into v: v <- readRDS('/path/to/test.rds')
  2. Run code from previous comment, which in my case provokes the error.
  3. Optionally restart R (saving workspace) and rerun last statement only.

from dwnominate.

wmay avatar wmay commented on June 20, 2024

I wasn't expecting people to put tibbles into the rollcall objects. That was the issue. Does the new version fix it for you?

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

Unfortunately I still have the same problem with the latest HEAD. I will try to see if I can figure out a workaround on my end.

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

What does the trick is to also convert the legis.data parameter to rollcall() using as.data.frame(). Possibly dwnominate could somehow do this or report a more comprehensible error message if it detects this issue.

from dwnominate.

wmay avatar wmay commented on June 20, 2024

Yup, that's what I did. 7ccb8b0

(There's a separate issue if your list only has two rollcalls, but I assume your real data has more sessions.)

from dwnominate.

knutwannheden avatar knutwannheden commented on June 20, 2024

Maybe I have to test it again, but I am quite certain that I still had the same problem with your fix in place and I had to add the as.data.frame() call on top of that in my code. So possibly there is another usage of the parameter which requires this.

from dwnominate.

Related Issues (20)

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.