Skip to content

Commit dd3dfbe

Browse files
authored
Merge pull request #125 from koheiw/remove-experimental
Remove experimental functions
2 parents 8fce0c3 + 6592343 commit dd3dfbe

4 files changed

Lines changed: 4 additions & 101 deletions

File tree

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Changes in v1.5.2
22

33
* Add `nested_weight` to `textmodel_lss()` and `as.textmodel_lss()` to perform dictionary-like analysis.
4-
* Remove `auto_weight` from `textmodel_lss()`.
4+
* Remove `auto_weight` from `textmodel_lss()` and `cut` from `predict()`.
55

66
## Changes in v1.5.1
77

R/predict.R

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
#' @param newdata a dfm on which prediction should be made.
66
#' @param se_fit if `TRUE`, returns standard error of document scores.
77
#' @param density if `TRUE`, returns frequency of polarity words in documents.
8-
#' @param cut a vector of one or two percentile values to dichotomized polarty
9-
#' scores of words. When two values are given, words between them receive zero
10-
#' polarity.
118
#' @param rescale if `TRUE`, normalizes polarity scores using `scale()`.
129
#' @param min_n set the minimum number of polarity words in documents.
1310
#' @param ... not used
1411
#' @details Polarity scores of documents are the means of polarity scores of
1512
#' words weighted by their frequency. When `se_fit = TRUE`, this function
1613
#' returns the weighted means, their standard errors, and the number of
1714
#' polarity words in the documents. When `rescale = TRUE`, it converts the raw
18-
#' polarity scores to z sores for easier interpretation. When `rescale =
19-
#' FALSE` and `cut` is used, polarity scores of documents are bounded by
20-
#' \[-1.0, 1.0\].
15+
#' polarity scores to z sores for easier interpretation.
2116
#'
2217
#' Documents tend to receive extreme polarity scores when they have only few
2318
#' polarity words. This is problematic when LSS is applied to short documents
@@ -30,7 +25,7 @@
3025
#' @export
3126
predict.textmodel_lss <- function(object, newdata = NULL, se_fit = FALSE,
3227
density = FALSE, rescale = TRUE,
33-
cut = NULL, min_n = 0L, ...){
28+
min_n = 0L, ...){
3429

3530

3631
(function(se.fit, recaling, ...) unused_dots(...))(...) # trap deprecated args
@@ -45,11 +40,6 @@ predict.textmodel_lss <- function(object, newdata = NULL, se_fit = FALSE,
4540
}
4641
min_n <- check_integer(min_n, min = 0)
4742

48-
if (!is.null(cut)) {
49-
cut <- check_double(cut, min = 0, max = 1, min_len = 1, max_len = 2)
50-
object$beta <- cut_beta(object$beta, cut)
51-
}
52-
5343
beta <- Matrix(object$beta, nrow = 1, sparse = TRUE,
5444
dimnames = list(NULL, names(object$beta)))
5545

@@ -101,13 +91,4 @@ predict.textmodel_lss <- function(object, newdata = NULL, se_fit = FALSE,
10191
}
10292
}
10393

104-
cut_beta <- function(x, p = 0.5) {
105-
q <- c(-Inf, quantile(x, p, na.rm = TRUE), Inf)
106-
v <- as.integer(cut(x, q))
107-
beta <- double(length(x))
108-
beta[v == min(v)] <- -1.0
109-
beta[v == max(v)] <- 1.0
110-
names(beta) <- names(x)
111-
return(beta)
112-
}
11394

man/predict.textmodel_lss.Rd

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-textmodel_lss.R

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -399,78 +399,6 @@ test_that("se_fit is working", {
399399
expect_identical(pred1, pred2)
400400
})
401401

402-
test_that("cut is working", {
403-
404-
skip_on_cran() # takes to much time
405-
406-
p0 <- predict(lss_test, rescale = TRUE, min_n = 10)
407-
p1 <- predict(lss_test, cut = 0.5, rescale = TRUE)
408-
expect_true(min(p1, na.rm = TRUE) < -1)
409-
expect_true(max(p1, na.rm = TRUE) > 1)
410-
expect_equal(cor(p0, p1, use = "pair"), 0.59, tolerance = 0.01)
411-
412-
p2 <- predict(lss_test, cut = 0.5, rescale = FALSE)
413-
expect_true(min(p2, na.rm = TRUE) >= -1)
414-
expect_true(max(p2, na.rm = TRUE) <= 1)
415-
expect_equal(cor(p0, p2, use = "pair"), 0.59, tolerance = 0.01)
416-
417-
p3 <- predict(lss_test, cut = 0.5, rescale = FALSE, min_n = 10)
418-
expect_true(min(p3, na.rm = TRUE) >= -1)
419-
expect_true(max(p3, na.rm = TRUE) <= 1)
420-
expect_equal(cor(p0, p3, use = "pair"), 0.73, tolerance = 0.01)
421-
422-
p4 <- predict(lss_test, cut = 0.75, rescale = FALSE, min_n = 10)
423-
expect_true(min(p4, na.rm = TRUE) >= -1)
424-
expect_true(max(p4, na.rm = TRUE) <= 1)
425-
expect_equal(cor(p0, p4, use = "pair"), 0.33, tolerance = 0.01)
426-
427-
p5 <- predict(lss_test, cut = c(0.25, 0.75), rescale = FALSE, min_n = 10)
428-
expect_true(min(p5, na.rm = TRUE) >= -1)
429-
expect_true(max(p5, na.rm = TRUE) <= 1)
430-
expect_equal(cor(p0, p5, use = "pair"), 0.77, tolerance = 0.01)
431-
432-
p6 <- predict(lss_test, cut = c(0.75, 0.25), rescale = FALSE, min_n = 10)
433-
expect_identical(p5, p6)
434-
435-
expect_error(
436-
predict(lss_test, cut = 1.5),
437-
"The value of cut must be between 0 and 1"
438-
)
439-
expect_error(
440-
predict(lss_test, cut = -0.1),
441-
"The value of cut must be between 0 and 1"
442-
)
443-
expect_error(
444-
predict(lss_test, cut = c(0.1, 0.5, 0.9)),
445-
"The length of cut must be between 1 and 2"
446-
)
447-
448-
expect_equal(
449-
LSX:::cut_beta(c(1.1, -1.2, 0.5, 0.3, -0.2, -0.5)),
450-
c(1, -1, 1, 1, -1, -1)
451-
)
452-
expect_equal(
453-
LSX:::cut_beta(c(1.1, -1.2, 0.5, 0.3, -0.2, -0.5), c(0.2, 0.8)),
454-
c(1, -1, 0, 0, 0, -1)
455-
)
456-
457-
beta <- rnorm(nfeat(dfmt_test), sd = 0.1)
458-
names(beta) <- featnames(dfmt_test)
459-
beta2 <- LSX:::cut_beta(beta, c(0.2, 0.8))
460-
461-
lss1 <- as.textmodel_lss(beta)
462-
lss2 <- as.textmodel_lss(beta2)
463-
expect_equal(names(lss1$beta), names(lss2$beta))
464-
465-
pred0 <- predict(lss1, dfmt_test, se_fit = TRUE)
466-
pred1 <- predict(lss1, dfmt_test, cut = c(0.2, 0.8), se_fit = TRUE)
467-
pred2 <- predict(lss2, dfmt_test, se_fit = TRUE)
468-
469-
expect_equal(pred0$n, pred1$n)
470-
expect_equal(pred0$n, pred2$n)
471-
expect_equal(pred1$fit, pred2$fit)
472-
})
473-
474402
test_that("rescaling still works", {
475403

476404
expect_warning({

0 commit comments

Comments
 (0)