tzuliu / ooc

This is a repository for the project of "Ordered Optimal Classification"
MIT License
8 stars 2 forks source link

Error when fitting one-dimensional model #2

Closed jacksantucci closed 5 years ago

jacksantucci commented 5 years ago

I am updating my post. The error below occurs when fitting a one-dimensional model in which one or more votes are dropped. Otherwise, it does not occur. Thanks!

Error in if (onedim.classification.errors[i, j] == 1) correct.class.binary[i, : missing value where TRUE/FALSE needed

tzuliu commented 5 years ago

Could you send us the data and your full code so we can have a closer look? Thanks!

jacksantucci commented 5 years ago

You bet! Here is the error, and the attached files will replicate it.

ooc1 <- ooc(votes, dims=1, polarity=1148)

Preparing to run Optimal Classification...

Checking data...

... 1 of 1212 total members dropped.

Votes dropped: ... 1 of 117 total votes dropped.

Running Optimal Classification...

Generating Start Coordinates... Running Edith Algorithm... Permuting adjacent legislator pairs... Permuting adjacent legislator triples...

Optimal Classification completed successfully. Optimal Classification took 97.635 seconds to execute.

Error in if (onedim.classification.errors[i, j] == 1) correct.class.binary[i, : missing value where TRUE/FALSE needed

On Thu, May 16, 2019 at 5:55 PM Tzu-Ping Liu notifications@github.com wrote:

Could you send us the data and your full code so we can have a closer look? Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tzuliu/ooc/issues/2?email_source=notifications&email_token=AADBIBL7PHV7JXZDLOSQVO3PVXJ3JA5CNFSM4HLEZK7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVTFHGY#issuecomment-493245339, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBIBNXPSAFJRD6FCOY67LPVXJ3JANCNFSM4HLEZK7A .

tzuliu commented 5 years ago

Through your codes, there are two issues I can identify. First, if you checked the demonstration code here, you should see that we removed all the NA's first, which you did not do. Second, the parameter polarity of the function ooc is to assign one of the respondents as the "anchor" for estimation, and you set that parameter as 1148, which means you want the 1148th respondent as the anchor. However, if you checked your data, 1148 is not one of the indices of the rows. So you have to fix this first. Furthermore, once you remove all the rows with NA's and re-index the rows, you will find that there are totally only 595 respondents so you can only set polarity in between 1 to 595.

Below are the codes I fixed:

library(ooc)

load("votes.Rdta")

votes <- votes[complete.cases(votes), ]

rownames(votes) <- 1:nrow(votes)

ooc1 <- ooc(votes, dims=1, polarity=100)
christopherdanielhare commented 5 years ago

Thanks -- the issue has to deal with how OOC handles lopsided responses to issue scale questions. In your dataset, the problem is with the scale in the 31st column:

> table(votes[,31])

  1   2   3   4 
647 466  85   1

The response option 4 is lopsided. Right now, it's left to the user's discretion about whether to (a) drop the entire scale, (b) recode the lopsided response into a neighboring category, or (3) recode the lopsided response option as missing data.

We'll need to address this in a future release (either by deciding on one of the options and running it automatically in the wrapper or adding an argument that allows the user to choose). Until then this issue is best dealt with by processing the data before passing it to OOC.