Skip to content

Conversation

@YeWang1576
Copy link
Collaborator

Add the one-dimensional and two-dimensional negative binomial model, as well as the two-dimensional Poisson model

Copy link
Contributor

@kbenoit kbenoit left a 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_values argument 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 NA for them to be estimated. Please explain more how these are implemented and used by the model.

  • The helper functions such as predict() and coef() 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 for textmodel_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:

  1. 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 = 1 argument that can take a 2 for the 2D case, then we can use one function. But then the dir will need four, not two values.
  2. I think we should define a new return object class called textmodel_wordfish2d for two-dimensional objects, then we can write separate predict() and coef() etc methods for this variant (and solving one of the issues above). It also means we could write a textmodel_scale2d.textmodel_wordfish2d() function for this - plus a method for textmodel_ca objects.
  3. 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
Copy link
Contributor

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.

#' @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
Copy link
Contributor

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?

#' @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).
Copy link
Contributor

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
Copy link
Contributor

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))
}
Copy link
Contributor

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),
Copy link
Contributor

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.

@YeWang1576
Copy link
Collaborator Author

@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
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #32 (639f6b8) into master (34017dc) will decrease coverage by 5.55%.
The diff coverage is 28.02%.

❗ Current head 639f6b8 differs from pull request most recent head 989ef98. Consider uploading reports for the commit 989ef98 to get more accurate results

@@            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     
Impacted Files Coverage Δ
src/wordfish_dense.cpp 40.91% <25.00%> (-59.09%) ⬇️
R/textmodel_wordfish.R 79.41% <65.51%> (-4.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17f1c84...989ef98. Read the comment docs.

@kbenoit kbenoit changed the title merge Add 2-dimensional wordfish model and 1- and 2-dimensional NB wordfish models Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants