scale.sentomeasures: Scaling and centering of sentiment measures

Description Usage Arguments Details Value Author(s) Examples

View source: R/sentomeasures_methods.R

Description

Scales and centers the sentiment measures from a sentomeasures object, column-per-column. By default, the measures are normalized. NAs are removed first.

Usage

1
2
## S3 method for class 'sentomeasures'
scale(x, center = TRUE, scale = TRUE)

Arguments

x

a sentomeasures object created using sento_measures.

center

a logical or a numeric vector, see documentation for the generic scale. Alternatively, one can provide a matrix of dimensions nobs(sentomeasures) times 1 or nmeasures(sentomeasures) with values to add to each individual observation.

scale

a logical or a numeric vector, see documentation for the generic scale. Alternatively, one can provide a matrix of dimensions nobs(sentomeasures) times 1 or nmeasures(sentomeasures) with values to divide each individual observation by.

Details

If one of the arguments center or scale is a matrix, this operation will be applied first, and eventual other centering or scaling is computed on that data.

Value

A modified sentomeasures object, with the measures replaced by the scaled measures as well as updated statistics.

Author(s)

Samuel Borms

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
data("usnews", package = "sentometrics")
data("list_lexicons", package = "sentometrics")
data("list_valence_shifters", package = "sentometrics")

set.seed(505)

# construct a sentomeasures object to start with
corpus <- sento_corpus(corpusdf = usnews)
corpusSample <- quanteda::corpus_sample(corpus, size = 500)
l <- sento_lexicons(list_lexicons[c("LM_en", "HENRY_en")], list_valence_shifters[["en"]])
ctr <- ctr_agg(howTime = c("equal_weight", "linear"), by = "year", lag = 3)
sentomeasures <- sento_measures(corpusSample, l, ctr)

# scale sentiment measures to zero mean and unit standard deviation
sc1 <- scale(sentomeasures)

n <- nobs(sentomeasures)
m <- nmeasures(sentomeasures)

# add a matrix
sc2 <- scale(sentomeasures, center = matrix(runif(n * m), n, m), scale = FALSE)

# divide every row observation based on a one-column matrix, then center
sc3 <- scale(sentomeasures, center = TRUE, scale = matrix(runif(n)))

sborms/sentometrics documentation built on Dec. 26, 2018, 6:25 p.m.