Skip to content

Commit

Permalink
- Introduction to v0.1.2. There are too many changes to document. The…
Browse files Browse the repository at this point in the history
… code was went through line by line, and commented thoroughly. Some objects, such as timeline, have been removed because they were redundant. Duplicated code has also been removed. An important improvement was the binning of the STFDF. Now all time has to be POSIXct.
  • Loading branch information
andrewzm committed Mar 31, 2017
1 parent f4138f9 commit f21d495
Show file tree
Hide file tree
Showing 57 changed files with 4,944 additions and 3,169 deletions.
5 changes: 3 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ bigstudies
^inla-mesher-functions
^issues
^PBSmapping
^R/rhipe_fns.R$
.log$
.bbl$
.concordance.tex$
.synctex.gz$
^README.md$
^devel/devel.R$
^R/rhipe_fns.R$
^cran-comments.md$
^\.\.pdf$
^paper
Expand All @@ -23,4 +24,4 @@ bigstudies
^vignettes/figures
rhipe_fns.R$
^Permissions
^pres
^pres
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: FRK
Type: Package
Title: Fixed Rank Kriging
Version: 0.1.1
Version: 0.1.2
Date: 2017-03-06
Authors@R: c(
person("Andrew", "Zammit-Mangion", , "[email protected]", c("aut", "cre")),
Expand Down Expand Up @@ -57,5 +57,5 @@ Additional_repositories: https://andrewzm.github.io/dggrids-repo,
License: GPL (>= 2.1)
NeedsCompilation: yes
LazyData: true
RoxygenNote: 6.0.0
RoxygenNote: 6.0.1
LinkingTo: Rcpp
10 changes: 8 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,Basis)
S3method(as.data.frame,TensorP_Basis)
export(Basis_as_data.frame)
export(EmptyTheme)
export(Euclid_dist)
export(FRK)
Expand All @@ -11,6 +14,7 @@ export(STplane)
export(STsphere)
export(SpatialPolygonsDataFrame_to_df)
export(TensorP)
export(TensorP_Basis_as_data.frame)
export(auto_BAUs)
export(auto_basis)
export(df_to_SpatialPolygons)
Expand All @@ -30,10 +34,11 @@ export(plane)
export(radial_basis)
export(real_line)
export(show_basis)
export(sp_to_ST_basis)
export(sphere)
export(timeline)
export(type)
exportMethods("$")
exportMethods("$<-")
exportMethods("data.frame<-")
import(Matrix)
import(dplyr)
import(ggplot2)
Expand Down Expand Up @@ -64,6 +69,7 @@ importFrom(stats,optim)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(stats,terms)
importFrom(stats,time)
importFrom(stats,var)
importFrom(utils,data)
useDynLib(FRK, .registration=TRUE)
75 changes: 35 additions & 40 deletions R/AllClass.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#### CLASS DEFINITIONS ######

### Manifolds and measures
#' @docType class
#' @title measure
#' @docType class
#' @title measure
#'
#' @description Measure class used for defining measures used to compute distances between points in objects constructed with the \code{FRK} package.
#' @details An object of class \code{measure} contains a distance function and a variable \code{dim} with the dimensions of the Riemannian manifold over which the distance is computed. By default, distance functions used are those extracted from the package \code{fields}.
#' @details An object of class \code{measure} contains a distance function and a variable \code{dim} with the dimensions of the Riemannian manifold over which the distance is computed.
#' @keywords Manifolds, spheres, planes
setClass("measure",representation(dist="function",dim="integer"),
prototype(dist=dist,dim=2L))

#' @docType class
#' @title manifold
#' @docType class
#' @title manifold
#' @description The class \code{manifold} is virtual; other manifold classes inherit from this class.
#' @details A \code{manifold} object is characterised by a character variable \code{type}, which contains a description of the manifold, and a variable \code{measure} of type \code{measure}. A typical measure is the Euclidean distance.
#'
#' \code{FRK} supports five manifolds; the real line (in one dimension), instantiated by using \code{real_line()}; the 2D plane, instantiated by using \code{plane()}; the 2D-sphere surface S2, instantiated by using \code{sphere()}; the R2 space-time manifold, instantiated by using \code{STplane()}, and the S2 space-time manifold, instantiated by using \code{STsphere()}. User-specific manifolds can also be specified, however helper functions that are manifold specific, such as \code{auto_BAU} and \code{auto_BAUs} and \code{auto_basis} only work with the pre-configured manifolds. Importantly, one can change the distance function used on the manifold to synthesise anisotropy or heterogeneity.
#' \code{FRK} supports five manifolds; the real line (in one dimension), instantiated by using \code{real_line()}; the 2D plane, instantiated by using \code{plane()}; the 2D-sphere surface S2, instantiated by using \code{sphere()}; the R2 space-time manifold, instantiated by using \code{STplane()}, and the S2 space-time manifold, instantiated by using \code{STsphere()}. User-specific manifolds can also be specified, however helper functions that are manifold specific, such as \code{auto_BAUs} and \code{auto_basis} only work with the pre-configured manifolds. Importantly, one can change the distance function used on the manifold to synthesise anisotropy or heterogeneity. See the vignette for one such example.
#'
#' @keywords Manifolds, spheres, planes
setClass("manifold",representation(type="character", measure = "measure","VIRTUAL"))
Expand All @@ -24,16 +24,9 @@ setClass("manifold",representation(type="character", measure = "measure","VIRTUA
#' @aliases STmanifold-class
setClass("STmanifold",contains="manifold")



#' @rdname manifold-class
#' @aliases sphere-class
setClass("sphere",representation(radius="numeric"),contains="manifold")

#' @rdname manifold-class
#' @aliases STsphere-class
setClass("STsphere",representation(radius="numeric"),contains="STmanifold")

#' @aliases real_line-class
setClass("real_line",contains="manifold")

#' @rdname manifold-class
#' @aliases plane-class
Expand All @@ -44,62 +37,69 @@ setClass("plane",contains="manifold")
setClass("STplane",contains="STmanifold")

#' @rdname manifold-class
#' @aliases real_line-class
setClass("real_line",contains="manifold")
#' @aliases sphere-class
setClass("sphere",representation(radius="numeric"),contains="manifold")

#' @rdname manifold-class
#' @aliases timeline-class
setClass("timeline",contains="manifold")
#' @aliases STsphere-class
setClass("STsphere",representation(radius="numeric"),contains="STmanifold")

#### Basis functions ####
#' @docType class
#' @title Basis functions
#'
#' @description An object of class \code{Basis} contains the basis functions used to construct the matrix \eqn{S} in fixed-rank kriging. It contains five slots, described below.
#' @description An object of class \code{Basis} contains the basis functions used to construct the matrix \eqn{S} in FRK. It contains five slots, described below.
#' @slot manifold an object of class \code{manifold} that contains information on the manifold and the distance measure used on the manifold. See \code{\link{manifold-class}} for more details
#' @slot n the number of basis functions in this set
#' @slot fn a list of length \code{n}, with each item the function of a specific basis function
#' @slot pars a list of parameters where the \eqn{i}-th item in the list contains the parameters of the \eqn{i}-th basis function, \code{fn[[i]]}
#' @slot df a data frame containing other attributes specific to each basis function (for example the geometric centre of the local basis function)
#' @details Basis functions are a central component of \code{FRK}, and the package is designed to work with user-defined specifications of these. For convenience, however, several functions are available to aid the user to construct a basis set for a given set of data points. Please see \code{\link{auto_basis}} for more details. The function \code{\link{local_basis}} helps the user construct a set of local basis functions (e.g., bisquare functions) from a collection of locations and scale parameters.
#' @keywords Basis functions
#' @rdname Basisclass
#' @rdname Basis-class
setClass("Basis_obj", representation(n = "numeric","VIRTUAL"))

#' @rdname Basisclass
#' @rdname Basis-class
setClass("Basis",contains="Basis_obj", representation(manifold="manifold",fn="list",pars="list", df="data.frame"))

#' @rdname Basisclass
#' @rdname Basis-class
setClass("TensorP_Basis", contains="Basis_obj", representation(Basis1="Basis",Basis2="Basis",n = "integer", df = "data.frame"))


#' @title Spatial Random Effects class
#' @description This is the central class definition of the \code{FRK} package, containing the model and all other information required for estimation and prediction.
#' @details The spatial random effects (SRE) model is the model employed in Fixed Rank Kriging, and the \code{SRE} object contains all information required for estimation and prediction from spatial data. Object slots contain both other objects (for example, an object of class \code{Basis}) and matrices derived from these objects (for example, the matrix \eqn{S}) in order to facilitate computations.
#'
#' @slot f formula used to define the SRE object. All covariates employed need to be specified in the object \code{BAUs}
#'@slot data the original data from which the model's parameters are estimated
#'@slot basis object of class \code{Basis} used to construct the matrix \eqn{S}
#'@slot BAUs object of class \code{SpatialPolygonsDataFrame}, \code{SpatialPixelsDataFrame} of \code{STFDF} that contains the Basic Areal Units (BAUs) that are used to both (i) project the data onto a common discretisation if they are point-referenced and (ii) provide a BAU-to-data relationship if the data has a spatial footprint
#' @slot f formula used to define the SRE object. All covariates employed need to be specified in the object \code{BAUs}
#' @slot S matrix constructed by evaluating the basis functions at all BAUs affected by the data
#' @slot Ve measurement-error variance-covariance matrix (typically diagonal)
#' @slot Vfs fine-scale variance-covariance matrix (typically diagonal) up to a constant of proportionality estimated in the framework
#' @slot S matrix constructed by evaluating the basis functions at all the data locations (of class \code{Matrix})
#' @slot S0 matrix constructed by evaluating the basis functions at all BAUs (of class \code{Matrix})
#' @slot D_basis list of distance-matrices of class \code{Matrix}, one for each basis-function resolution
#' @slot Ve measurement-error variance-covariance matrix (typically diagonal and of class \code{Matrix})
#' @slot Vfs fine-scale variance-covariance matrix at the data locations (typically diagonal and of class \code{Matrix}) up to a constant of proportionality estimated in the framework
#' @slot Vfs_BAUs fine-scale variance-covariance matrix at the BAU centroids (typically diagonal and of class \code{Matrix}) up to a constant of proportionality estimated in the framework
#' @slot Qfs_BAUs fine-scale precision matrix at the BAU centroids (typically diagonal and of class \code{Matrix}) up to a constant of proportionality estimated in the framework
#' @slot Z vector of observations (of class \code{Matrix})
#' @slot Cmat incidence matrix mapping the observations to the BAUs
#' @slot X matrix of covariates
#' @slot K_type type of prior covariance matrix of random effects. Can be "block-exponential" (correlation between effects decays as a function of distance between the basis-function centroids), or "unstructured" (all elements in \code{K} are unknown and need to be estimated)
#' @slot mu_eta updated expectation of random effects (estimated)
#' @slot S_eta updated covariance matrix of random effects (estimated)
#' @slot Q_eta updated precision matrix of random effects (estimated)
#' @slot Khat prior covariance matrix of random effects (estimated)
#' @slot Khat_inv prior covariance matrix of random effects (estimated)
#' @slot alphahat covariates weights (estimated)
#' @slot sigma2fshat fine-scale variation scaler (estimated)
#' @slot Khat_inv prior precision matrix of random effects (estimated)
#' @slot alphahat fixed-effect regression coefficients (estimated)
#' @slot sigma2fshat fine-scale variation scaling (estimated)
#' @slot fs_model type of fine-scale variation (independent or CAR-based). Currently only "ind" is permitted
#' @keywords Spatial random effects, fixed rank kriging
setClass("SRE",representation(data="list",
basis="Basis_obj",
BAUs="ANY", # should be SpatialPolygonsDataFrame, SpatialPixelsDataFrame or STFDF
f = "formula",
S = "Matrix",
S0 = "Matrix",
D_basis = "list",
Ve = "Matrix",
Vfs = "Matrix",
Vfs_BAUs = "Matrix",
Expand All @@ -108,16 +108,11 @@ setClass("SRE",representation(data="list",
Cmat = "Matrix",
X = "Matrix",
mu_eta = "Matrix",
mu_xi = "Matrix",
S_eta = "Matrix",
Khat = "Matrix",
alphahat = "Matrix",
Q_eta = "Matrix",
K_type = "character",
Khat = "Matrix",
Khat_inv = "Matrix",
B_run = "Matrix",
v_run = "Matrix",
alphahat = "Matrix",
sigma2fshat = "numeric",
fs_model = "character",
D_basis = "list",
K_type = "character",
lambda = "numeric"))
fs_model = "character"))
Loading

0 comments on commit f21d495

Please sign in to comment.