From 61d567072ad1afaf7aca8e76add26c4b6dc11d72 Mon Sep 17 00:00:00 2001 From: Brandon Stewart Date: Fri, 3 Mar 2017 10:44:10 -0500 Subject: [PATCH 1/2] Small documentation changes --- DESCRIPTION | 2 +- R/stm-package.R | 4 ++-- man/gadarian.Rd | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6dc0da45f..31d4752c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: stm Type: Package Title: Estimation of the Structural Topic Model Version: 1.2.1 -Date: 2017-03-01 +Date: 2017-03-03 Author: Margaret Roberts [aut, cre], Brandon Stewart [aut, cre], Dustin Tingley [aut, cre], diff --git a/R/stm-package.R b/R/stm-package.R index 9f7cfbbf4..2963a8e9f 100644 --- a/R/stm-package.R +++ b/R/stm-package.R @@ -65,11 +65,11 @@ NULL #' @docType data #' @format A data frame with 351 observations on the following 3 variables. #' \describe{ -#' \item{\code{MetaID"}}{A numeric vector containing identification +#' \item{\code{MetaID}}{A numeric vector containing identification #' numbers; not used for analysis} #' \item{\code{treatment}}{A numeric vector #' indicating treatment condition} -#' \item{\code{pid_rep"}}{A numeric vector of +#' \item{\code{pid_rep}}{A numeric vector of #' party identification} #' \item{\code{open.ended.response}}{A character vector #' of the subject's open ended response} diff --git a/man/gadarian.Rd b/man/gadarian.Rd index c73f00126..7a5281395 100644 --- a/man/gadarian.Rd +++ b/man/gadarian.Rd @@ -7,11 +7,11 @@ \title{Gadarian and Albertson data} \format{A data frame with 351 observations on the following 3 variables. \describe{ -\item{\code{MetaID"}}{A numeric vector containing identification +\item{\code{MetaID}}{A numeric vector containing identification numbers; not used for analysis} \item{\code{treatment}}{A numeric vector indicating treatment condition} -\item{\code{pid_rep"}}{A numeric vector of +\item{\code{pid_rep}}{A numeric vector of party identification} \item{\code{open.ended.response}}{A character vector of the subject's open ended response} From b28d44aa4ab108236a0e4abf001ea3951b479148 Mon Sep 17 00:00:00 2001 From: Brandon Stewart Date: Fri, 3 Mar 2017 10:55:11 -0500 Subject: [PATCH 2/2] quanteda test changes --- R/stm.R | 3 +++ man/stm.Rd | 3 +++ tests/testthat/Rplots.pdf | Bin 0 -> 4670 bytes tests/testthat/test-quanteda-stm.R | 27 ++++++++++++++++----------- 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/Rplots.pdf diff --git a/R/stm.R b/R/stm.R index 684854d65..96d6ef700 100644 --- a/R/stm.R +++ b/R/stm.R @@ -340,11 +340,14 @@ #' prevalence=~treatment + s(pid_rep), data=out$meta) #' #' #The same example using quanteda instead of tm via textProcessor() +#' #Note this example works with quanteda version 0.9.9-31 and later #' require(quanteda) #' gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") #' gadarian_dfm <- dfm(gadarian_corpus, #' remove = stopwords("english"), #' stem = TRUE) +#' stm_from_dfm <- stm(gadarian_dfm, K = 3, prevalence = ~treatment + s(pid_rep), +#' data = docvars(gadarian_corpus)) #' #' #An example of restarting a model #' mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), diff --git a/man/stm.Rd b/man/stm.Rd index 58a815bc4..af6004841 100644 --- a/man/stm.Rd +++ b/man/stm.Rd @@ -352,11 +352,14 @@ mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), data=out$meta) #The same example using quanteda instead of tm via textProcessor() +#Note this example works with quanteda version 0.9.9-31 and later require(quanteda) gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") gadarian_dfm <- dfm(gadarian_corpus, remove = stopwords("english"), stem = TRUE) +stm_from_dfm <- stm(gadarian_dfm, K = 3, prevalence = ~treatment + s(pid_rep), + data = docvars(gadarian_corpus)) #An example of restarting a model mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..05f8691482ee04f3e7f4d91da89f080c2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XREziml!`4n4lon?~q={VDL3crAz7abzekYl)pHyo}JFoxzZDUuiQAV5l92U3c1@lFy;D&Iy9?ry5mND)IS4af8yY)hcmw zxdo=;#sN~o#zn@mMkB;YLLK8;hyAtFw86_|(1Z4DJl(F{?p^=v(3^_=()J2;P<-gX z!&)*YR=+j*#<3e8A6sDTEh`cp7(X<25^))Dg)GX;XJ}NT&jv~Mroly?pK=FZ)dbcQ ze_VXsYnNwh@3clJcAxJEda~ZhkrNY7yGc{uIH01Zx*FE8UR`CFbHD7vv(R^;A0pz| zXdTHN9r9`NP?2BZUFwp1Lw(ywKv?hFCVU|=uj0mm?Xi-v2f}VKK7D?6GB)_v2gzkL zFNUixXL-(D{u!5H^_SOrq&_9j9ytC>Kv_ley}a?@w)r*jUM)Ma%lm)@LdDTQz7(>4{IM!1P*`REZNm5ob2Y|`muV# z?>_ly=tRVCrGk*!tIHV!B$=VurYw}=OGFXi-Chb>H@GT`uF`o015JhBLE~4j`(>2 zD$2@=%77>E6GJh#B&-V{{KSwdOda&!7!sk*6c+!$kgCj;!ap#SI#a^@15-r(%O3)T zWbQ-$+YW(J{}-l&K>jO+5=!-Nxll+L93CPumplMyjSGU9?+bv21WzJUow4cxS`mp9 cfVF(tstuWfAyKv}qok;cf=fxAGS`Fu2W&b2U;qFB literal 0 HcmV?d00001 diff --git a/tests/testthat/test-quanteda-stm.R b/tests/testthat/test-quanteda-stm.R index 7864d7466..01d4a20df 100644 --- a/tests/testthat/test-quanteda-stm.R +++ b/tests/testthat/test-quanteda-stm.R @@ -4,17 +4,22 @@ require(quanteda) test_that("Test that stm works on a quanteda dfm", { require(quanteda) - gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") - gadarian_dfm <- dfm(gadarian_corpus, - remove = stopwords("english"), - stem = TRUE) - set.seed(10012) # NYU :-) - stm_from_dfm <- stm(gadarian_dfm, - K = 3, - prevalence = ~treatment + s(pid_rep), - data = docvars(gadarian_corpus), - max.em.its=2) - expect_identical(class(stm_from_dfm), "STM") + if(utils::compareVersion(as.character(utils::packageVersion("quanteda")), "0.9.9-31") >= 0) { + gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") + gadarian_dfm <- dfm(gadarian_corpus, + remove = stopwords("english"), + stem = TRUE) + set.seed(10012) # NYU :-) + stm_from_dfm <- stm(gadarian_dfm, + K = 3, + prevalence = ~treatment + s(pid_rep), + data = docvars(gadarian_corpus), + max.em.its=2) + expect_identical(class(stm_from_dfm), "STM") + } else { + #basically if the version is old, just skip this test for now. + expect_identical("STM", "STM") + } }) test_that("Test that stm works on a classic stm object structure", {