Skip to content

Latest commit

 

History

History
104 lines (77 loc) · 4.18 KB

README.md

File metadata and controls

104 lines (77 loc) · 4.18 KB

fgm - Functional Graphical Models and Partial Separability

R package for Partially Separable Multivariate Functional Data and Functional Graphical Models Binder

Installation: simply run install.packages('fgm') in the R console

This repository contains a copy of the R-package fgm at CRAN:

https://cran.r-project.org/web/packages/fgm/index.html

The methods implemented here are based on the following paper:

(Draft copy) https://arxiv.org/abs/1910.03134

(journal link) ... under review...

posterFGM

Theory

A multivariate Gaussian process X is partially separable if there exists an orthonormal basis of such that the random vectors are mutually uncorrelated.

Univariate KL expansion possesses a potentially full inverse covariance structure. Under partial separability it remains block-diagonal.

Partial Separability Karhunen-Loeve expansion:

Univariate Karhunen-Loeve expansion:

Functions

fpca : Estimates the Karhunen-Loeve expansion for a partially separable multivariate Gaussian process.


## Variables
# Omega - list of precision matrices, one per eigenfunction
# Sigma - list of covariance matrices, one per eigenfunction
# theta - list of functional  principal component scores
# phi - list of eigenfunctions densely observed on a time grid
# y - list containing densely observed multivariate (p-dimensional) functional data 

install.packages('mvtnorm')
install.packages('fda')
install.packages('fgm')
library(mvtnorm)
library(fda)
library(fgm)

## Generate data y
 source(system.file("exec", "getOmegaSigma.R", package = "fgm"))
 theta = lapply(1:nbasis, function(b) t(rmvnorm(n = 100, sigma = Sigma[[b]])))
 theta.reshaped = lapply( 1:p, function(j){
     t(sapply(1:nbasis, function(i) theta[[i]][j,]))
 })
 phi.basis=create.fourier.basis(rangeval=c(0,1), nbasis=21, period=1)
 t = seq(0, 1, length.out = time.grid.length)
 chosen.basis = c(2, 3, 6, 7, 10, 11, 16, 17, 20, 21)
 phi = t(predict(phi.basis, t))[chosen.basis,]
 y = lapply(theta.reshaped, function(th) t(th)\%*\%phi)
 
## Solve  
 pfpca(y)

fgm: Estimates a sparse adjacency matrix representing the conditional dependency structure between features of a multivariate Gaussian process


## Variables
# Omega - list of precision matrices, one per eigenfunction
# Sigma - list of covariance matrices, one per eigenfunction
# theta - list of functional  principal component scores
# phi - list of eigenfunctions densely observed on a time grid
# y - list containing densely observed multivariate (p-dimensional) functional data 

install.packages('mvtnorm')
install.packages('fda')
install.packages('fgm')
library(mvtnorm)
library(fda)
library(fgm)
## Estimation using fgm package
## Generate Multivariate Gaussian Process
 source(system.file("exec", "getOmegaSigma.R", package = "fgm"))
 theta = lapply(1:nbasis, function(b) t(rmvnorm(n = 100, sigma = Sigma[[b]])))
 theta.reshaped = lapply( 1:p, function(j){
     t(sapply(1:nbasis, function(i) theta[[i]][j,]))
 })
 phi.basis=create.fourier.basis(rangeval=c(0,1), nbasis=21, period=1)
 t = seq(0, 1, length.out = time.grid.length)
 chosen.basis = c(2, 3, 6, 7, 10, 11, 16, 17, 20, 21)
 phi = t(predict(phi.basis, t))[chosen.basis,]
 y = lapply(theta.reshaped, function(th) t(th)\%*\%phi)
 
## Solve
 fgm(y, alpha=0.5, gamma=0.8)