-
Notifications
You must be signed in to change notification settings - Fork 6
Add 2-dimensional wordfish model and 1- and 2-dimensional NB wordfish models #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kbenoit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a welcome addition to the existing function that does two things:
- adds SEs for the other parameters, since the existing version only provided them for theta.
- adds an option to return second dimension estimates of the beta and theta parameters.
A few things that stand out, in addition to what I've noted in specific code-related comments:
-
Won't we need a second direction constraint for the 2D model? This could be a 3rd and 4th element, or a list of two length2 vectors.
-
The
prior_valuesargument seems really important but it's not documented. Since I suspect this is how the 2D model is identified, we need to make very clear how the 2D model must set this. Please document this and provide examples of how it is used. What is the setting for non-constrained parameters?NA? -
Related to priors, one possibility would be to consider the vector of betas and thetas for dimension two to be constrained at zero by default, and for these to be
NAfor them to be estimated. Please explain more how these are implemented and used by the model. -
The helper functions such as
predict()andcoef()will need more code for handling the 2D case. -
We should add a
textmodel_scale2d()as well for this case (and it can be used fortextmodel_ca()results). @koheiw and I can work on that one.
My preference then is to keep things as close as possible to the original function but extend it.
To things that @koheiw and I will also think about:
- Should this be part of the original function, or should we extend it to a new function? If we can unify the framework by making this work through the constraints, or using a
dims = 1argument that can take a2for the 2D case, then we can use one function. But then thedirwill need four, not two values. - I think we should define a new return object class called
textmodel_wordfish2dfor two-dimensional objects, then we can write separatepredict()andcoef()etc methods for this variant (and solving one of the issues above). It also means we could write atextmodel_scale2d.textmodel_wordfish2d()function for this - plus a method fortextmodel_caobjects. - This is written only for dense dfms, but @koheiw do you think the code could be adapted for the sparse version too?
| #' binomial model | ||
| #' @param dim2 a boolean variable that specifies whether to estimate the second | ||
| #' dimension of theta and beta | ||
| #' @param prior_values NEEDS DOCUMENTING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a description here.
R/textmodel_wordfish.R
Outdated
| #' @references Slapin, J. & Proksch, S.O. (2008). | ||
| #' [A Scaling Model | ||
| #' for Estimating Time-Series Party Positions from Texts](https://doi.org/10.1111/j.1540-5907.2008.00338.x). *American | ||
| #' @references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reference we can add for the 2D model?
R/textmodel_wordfish.R
Outdated
| #' @note In the rare situation where a warning message of "The algorithm did not | ||
| #' converge." shows up, removing some documents may work. | ||
| #' @seealso [predict.textmodel_wordfish()] | ||
| #' @references Slapin, J. & Proksch, S.O. (2008). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a description of the new return objects containing the word-level SEs and new parameters.
| #' Benchmark](http://doi.org/10.1093/pan/mpt002). *Political Analysis*, 21(3), | ||
| #' 298--313. | ||
| #' @author Benjamin Lauderdale, Haiyan Wang, and Kenneth Benoit | ||
| #' @examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some examples for the 2D case.
| "estimated.feature.scores" = as.coefficients_textmodel(head(coef(object)$features, n)) | ||
| ) | ||
| return(as.summary.textmodel(result)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predict will need modification for the 2D case.
| phi = as.numeric(result$phi), | ||
| se.theta = as.numeric(result$thetaSE) , | ||
| zeta = as.numeric(result$zeta), | ||
| theta2 = as.numeric(result$theta2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably makes more sense for the 2D case to return theta as an ndoc x 2 matrix instead of as two vectors of length ndoc. Same for the other parameters and SEs.
|
@kbenoit Thanks for the comments! I will work on the sparse version of the two-dimensional model and modify the dense version according to the suggestions as well. |
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
==========================================
- Coverage 64.27% 58.71% -5.56%
==========================================
Files 19 19
Lines 2536 2873 +337
==========================================
+ Hits 1630 1687 +57
- Misses 906 1186 +280
Continue to review full report at Codecov.
|
Add the one-dimensional and two-dimensional negative binomial model, as well as the two-dimensional Poisson model