Get cooccurrence statistics.
cooccurrences(.Object, ...)
# S4 method for class 'corpus'
cooccurrences(
.Object,
query,
cqp = is.cqp,
p_attribute = getOption("polmineR.p_attribute"),
boundary = NULL,
left = getOption("polmineR.left"),
right = getOption("polmineR.right"),
stoplist = NULL,
positivelist = NULL,
regex = FALSE,
keep = NULL,
cpos = NULL,
method = "ll",
mc = getOption("polmineR.mc"),
verbose = FALSE,
progress = FALSE,
...
)
# S4 method for class 'character'
cooccurrences(
.Object,
query,
cqp = is.cqp,
p_attribute = getOption("polmineR.p_attribute"),
boundary = NULL,
left = getOption("polmineR.left"),
right = getOption("polmineR.right"),
stoplist = NULL,
positivelist = NULL,
regex = FALSE,
keep = NULL,
cpos = NULL,
method = "ll",
mc = getOption("polmineR.mc"),
verbose = FALSE,
progress = FALSE,
...
)
# S4 method for class 'slice'
cooccurrences(
.Object,
query,
cqp = is.cqp,
left = getOption("polmineR.left"),
right = getOption("polmineR.right"),
p_attribute = getOption("polmineR.p_attribute"),
boundary = NULL,
stoplist = NULL,
positivelist = NULL,
keep = NULL,
method = "ll",
mc = FALSE,
progress = TRUE,
verbose = FALSE,
...
)
# S4 method for class 'partition'
cooccurrences(
.Object,
query,
cqp = is.cqp,
left = getOption("polmineR.left"),
right = getOption("polmineR.right"),
p_attribute = getOption("polmineR.p_attribute"),
boundary = NULL,
stoplist = NULL,
positivelist = NULL,
keep = NULL,
method = "ll",
mc = FALSE,
progress = TRUE,
verbose = FALSE,
...
)
# S4 method for class 'subcorpus'
cooccurrences(
.Object,
query,
cqp = is.cqp,
left = getOption("polmineR.left"),
right = getOption("polmineR.right"),
p_attribute = getOption("polmineR.p_attribute"),
boundary = NULL,
stoplist = NULL,
positivelist = NULL,
keep = NULL,
method = "ll",
mc = FALSE,
progress = TRUE,
verbose = FALSE,
...
)
# S4 method for class 'context'
cooccurrences(.Object, method = "ll", verbose = FALSE)
# S4 method for class 'partition_bundle'
cooccurrences(
.Object,
query,
verbose = FALSE,
mc = getOption("polmineR.mc"),
...
)
# S4 method for class 'Cooccurrences'
cooccurrences(.Object, query)
# S4 method for class 'remote_corpus'
cooccurrences(.Object, ...)
# S4 method for class 'remote_subcorpus'
cooccurrences(.Object, ...)A partition object, or a character vector with a CWB corpus.
Further parameters that will be passed into bigmatrix (applies only of big = TRUE).
A query, either a character vector to match a token, or a CQP query.
Defaults to is.cqp-function, or provide
TRUE/FALSE; relevant only if query is not NULL.
The p-attribute of the tokens/the query.
If provided, it will be checked that the corpus positions of windows do not extend beyond the left and right boundaries of the region defined by the s-attribute where the match occurs.
A single integer value defining the number of tokens to the
left of the query match to include in the context. Advanced usage: (a) If
left is a length-one character vector stating an s-attribute, the
context will be expanded to the (left) boundary of the region where the
match occurs. (b) If left is a named length-one integer vector, this
value is the number regions of the structural attribute referred to by the
vector's name to the left of the query match that are included in the
context.
A single integer value, a length-one character vector or a
named length-one integer value, with equivalent effects to argument
left.
Exclude a query hit from analysis if stopword(s) is/are in
context (relevant only if query is not NULL).
Character vector or numeric vector: include a query hit
only if token in positivelist is present. If positivelist is
a character vector, it is assumed to provide regex expressions (incredibly
long if the list is long) (relevant only if query is nut NULL)
A logical value, whether stoplist/positivelist are
interpreted as regular expressions.
list with tokens to keep
integer vector with corpus positions, defaults to NULL - then the corpus positions for the whole corpus will be used
The statistical test(s) to use (defaults to "ll").
whether to use multicore
A logical value, whether to be verbose.
A logical value, whether to output progress bar.
a cooccurrences-class object
Baker, Paul (2006): Using Corpora in Discourse Analysis. London: continuum, p. 95-120 (ch. 5).
Manning, Christopher D.; Schuetze, Hinrich (1999): Foundations of Statistical Natural Language Processing. MIT Press: Cambridge, Mass., pp. 151-189 (ch. 5).
See the documentation for the ll-method for an
explanation of the computation of the log-likelihood statistic.
use("polmineR")
#> ✔ corpus loaded: GERMAPARLMINI (version: 0.1.0 | build date: 2023-04-16)
use(pkg = "RcppCWB", corpus = "REUTERS")
#> ✔ corpus loaded: REUTERS
merkel <- partition("GERMAPARLMINI", interjection = "speech", speaker = ".*Merkel", regex = TRUE)
#> ... get cpos and strucs
merkel <- enrich(merkel, p_attribute = "word")
#> ... getting counts for p-attribute(s): word
cooc <- cooccurrences(merkel, query = "Deutschland")
# use subset-method to filter results
a <- cooccurrences("REUTERS", query = "oil")
b <- subset(a, !is.na(ll))
c <- subset(b, !word %in% tm::stopwords("en"))
d <- subset(c, count_coi >= 5)
e <- subset(c, ll >= 10.83)
format(e)
#> word count_coi count_ref exp_coi exp_ref ll rank_ll
#> <char> <int> <int> <num> <num> <num> <int>
#> 1: prices 27 20 9.23 37.77 33.05 1
#> 2: crude 13 7 3.93 16.07 19.62 2
#> 3: industry 8 2 1.96 8.04 16.97 3
#> 4: recent 5 1 1.18 4.82 11.33 4
# using pipe operator with subset
cooccurrences("REUTERS", query = "oil") %>%
subset(!is.na(ll)) %>%
subset(!word %in% tm::stopwords("en")) %>%
subset(count_coi >= 5) %>%
subset(ll >= 10.83) %>%
format()
#> word count_coi count_ref exp_coi exp_ref ll rank_ll
#> <char> <int> <int> <num> <num> <num> <int>
#> 1: prices 27 20 9.23 37.77 33.05 1
#> 2: crude 13 7 3.93 16.07 19.62 2
#> 3: industry 8 2 1.96 8.04 16.97 3
#> 4: recent 5 1 1.18 4.82 11.33 4
# generate datatables htmlwidget with buttons for export (Excel & more)
# (alternatively use openxlsx::write.xlsx())
# \donttest{
interactive_table <- cooccurrences("REUTERS", query = "oil") %>%
format() %>%
DT::datatable(
extensions = "Buttons",
options = list(dom = 'Btip', buttons = c("excel", "pdf", "csv"))
)
if (interactive()) show(interactive_table)
# }
# compute cooccurrences for a set of partitions
# (example not run by default to save time on test machines)
if (FALSE) { # \dontrun{
pb <- partition_bundle("GERMAPARLMINI", s_attribute = "speaker")
ps <- count(pb, query = "Deutschland")[Deutschland >= 25][["partition"]]
pb_min <- pb[ps]
y <- cooccurrences(pb_min, query = "Deutschland")
if (interactive()) y[[1]]
if (interactive()) y[[2]]
y2 <- corpus("GERMAPARLMINI") %>%
subset(speaker %in% c("Hubertus Heil", "Angela Dorothea Merkel")) %>%
split(s_attribute = "speaker") %>%
cooccurrences(query = "Deutschland")
} # }