Learn R Programming

TensorMCMC

TensorMCMC implements low-rank tensor regression for tensor predictors and scalar covariates using simple stochastic updates. It includes fast C++ routines for coefficient updates and prediction, and provides tools for cross-validation and error evaluation.

Installation

You can install the development version of TensorMCMC like so:

# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?

install.packages("devtools") 
devtools::install_github("Ritwick2012/TensorMCMC")

Example

This is a basic example which shows you how to solve a common problem:

library(TensorMCMC)
## basic example code

x.train <- array(rnorm(n*p*d), dim = c(n, p, d))
z.train <- matrix(rnorm(n*pgamma), n, pgamma)
y.train <- rnorm(n)

## Fit the tensor regression model
fit <- fit_tensor(x.train, z.train, y.train, rank = 2, nsweep = 50)

# Predict on training data
pred <- predict_tensor_reg(fit, x.train, z.train)

# Calculating RMSE
rmse_val <- rmse(pred, y.train)

Copy Link

Version

Install

install.packages('TensorMCMC')

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Ritwick Mondal

Last Published

January 12th, 2026

Functions in TensorMCMC (0.1.0)

cv.tensor.reg

Simple rank comparison via in-sample RMSE
update_beta_cpp

Update Beta Matrices Using C++ Random Walk
tensor.reg

Tensor Regression using Rcpp
getmean_cpp

Posterior Mean Using C++
predict_tensor_cpp

Predict Response Using Tensor Regression C++
predict.tensor.reg

Prediction from tensor regression (S3 method)
rigamma

Inverse-gamma random number generator
getmean

posterior mean for tensor regression
predict_tensor_reg

Predict tensor regression (wrapper)
rmse

root-mean-square error (RMSE)