Predict textmodel_wordscores

# S3 method for textmodel_wordscores
predict(
  object,
  newdata = NULL,
  se.fit = FALSE,
  interval = c("none", "confidence"),
  level = 0.95,
  rescaling = c("none", "lbg", "mv"),
  force = TRUE,
  ...
)

Arguments

object

a fitted Wordscores textmodel

newdata

dfm on which prediction should be made

se.fit

if TRUE, return standard errors as well

interval

type of confidence interval calculation

level

tolerance/confidence level for intervals

rescaling

"none" for "raw" scores; "lbg" for LBG (2003) rescaling; or "mv" for the rescaling proposed by Martin and Vanberg (2007). See References.

force

make the feature set of newdata conform to the model terms. The default of TRUE means that a fitted model can be applied to scale a dfm that does not contain a 1:1 match of features in the training and prediction data.

...

not used

Value

predict.textmodel_wordscores() returns a named vector of predicted document scores ("text scores" \(S_{vd}\) in LBG 2003), or a named list if se.fit = TRUE consisting of the predicted scores ($fit) and the associated standard errors ($se.fit). When interval = "confidence", the predicted values will be a matrix. This behaviour matches that of predict.lm.

Examples

tmod <- textmodel_wordscores(data_dfm_lbgexample, c(seq(-1.5, 1.5, .75), NA)) predict(tmod)
#> R1 R2 R3 R4 R5 #> -1.317931e+00 -7.395598e-01 -8.673617e-18 7.395598e-01 1.317931e+00 #> V1 #> -4.480591e-01
predict(tmod, rescaling = "mv")
#> Warning: More than two reference scores found with MV rescaling; using only min, max values.
#> R1 R2 R3 R4 R5 V1 #> -1.5000000 -0.8417280 0.0000000 0.8417280 1.5000000 -0.5099572
predict(tmod, rescaling = "lbg")
#> R1 R2 R3 R4 R5 V1 #> -1.58967683 -0.88488724 0.01632248 0.91753220 1.62232179 -0.52967149
predict(tmod, se.fit = TRUE)
#> $fit #> R1 R2 R3 R4 R5 #> -1.317931e+00 -7.395598e-01 -8.673617e-18 7.395598e-01 1.317931e+00 #> V1 #> -4.480591e-01 #> #> $se.fit #> [1] 0.006699613 0.011433605 0.012005250 0.011433605 0.006699613 0.011897667 #>
predict(tmod, se.fit = TRUE, interval = "confidence")
#> $fit #> fit lwr upr #> R1 -1.317931e+00 -1.33106234 -1.30480034 #> R2 -7.395598e-01 -0.76196925 -0.71715035 #> R3 -8.673617e-18 -0.02352986 0.02352986 #> R4 7.395598e-01 0.71715035 0.76196925 #> R5 1.317931e+00 1.30480034 1.33106234 #> V1 -4.480591e-01 -0.47137808 -0.42474008 #> #> $se.fit #> [1] 0.006699613 0.011433605 0.012005250 0.011433605 0.006699613 0.011897667 #>
predict(tmod, se.fit = TRUE, interval = "confidence", rescaling = "lbg")
#> $fit #> fit lwr upr #> R1 -1.58967683 -1.60567795 -1.5736757 #> R2 -0.88488724 -0.91219485 -0.8575796 #> R3 0.01632248 -0.01235043 0.0449954 #> R4 0.91753220 0.89022458 0.9448398 #> R5 1.62232179 1.60632067 1.6383229 #> V1 -0.52967149 -0.55808746 -0.5012555 #> #> $se.fit #> [1] 0.02448647 0.03025520 0.03095179 0.03025520 0.02448647 0.03082069 #>