esthcpp {sts}R Documentation

Estimate Hessian Matrix

Description

Estimates the Hessian matrix needed for the Variational E-step in C++

Usage

esthcpp(alpha_d, kappa_t, kappa_s, Sigma_Inv, doc, V, mv)

Arguments

alpha_d

the estimated alpha variables for the given document

kappa_t

the estimated kappa_t coefficients

kappa_s

the estimated kappa_s coefficients

Sigma_Inv

the inverse covariance matrix

doc

the sparse matrix representation of the document, with two rows, and columns equal to the number of unique vocabulary words in the document.

V

the size of the vocabulary

mv

the baseline log-transformed occurrence rate of each word in the corpus

Value

The Hessian matrix

Examples


library("tm"); library("stm"); library("sts")
temp<-textProcessor(documents=gadarian$open.ended.response,
metadata=gadarian, verbose = FALSE)
out <- prepDocuments(temp$documents, temp$vocab, temp$meta, verbose = FALSE)
X <- model.matrix(~1+out$meta$treatment + out$meta$pid_rep + 
out$meta$treatment * out$meta$pid_rep)[,-1]
X_seed <- as.matrix(out$meta$treatment)
sts_estimate <- sts(X, X_seed, out, numTopics = 3, maxIter = 10)
# for document #1: 
hessian <- esthcpp(alpha_d = sts_estimate$alpha[1,], kappa_t=sts_estimate$kappa$kappa_t, 
kappa_s=sts_estimate$kappa$kappa_s, Sigma_Inv = sts_estimate$sigma_inv, 
doc = out$documents[[1]], V=length(sts_estimate$vocab), mv = sts_estimate$mv)


[Package sts version 1.0 Index]