Skip to content

v0.5.1

Compare
Choose a tag to compare
@samuel-watson samuel-watson released this 17 Nov 18:01
· 151 commits to master since this release
  • Added Gaussian process approximations: Nearest neighbour Gaussian Process and Hilbert Space Gaussian Process. These can be specified with the prefix nngp_ and hsgp_, for example (1|nngp_sqexp(x,y)) and (1|hsgp_fexp(x,y)). Currently the HSGP only supports exponential and squared exponential covariance functions. An additional griddata class has been added to store location information and generate nearest neighbours. The approximation parameters (number of nearest neighbours or number of basis functions and boundary) are set in model$covariance$nngp_data() and model$covariance$hsgp_data(), respectively. There are two new C++ covariance classes derived from Covariance: nngpCovariance and hsgpCovariance. A new method for calculating the information matrix has been implemented for HSGP as the approximate covariance matrix is not positive definite and so cannot be inverted.
  • As a result of the new covariance types there are three types of model class in the package (i.e. Model<ModelBits<Covariance,LinearPredictor>> and so forth. The Rcpp modules have been updated; to maintain readability all exported functions require a type argument and the pointer is generated using the glmmrType struct which includes an std::variant for the different classes. This also simplifies future expansion with new classes (including in the rts2 package). A variant is also used as a generic capture for the return values. The generic structure of the Rcpp module functions is now:
// [[Rcpp::export]]
SEXP Model__P(SEXP xp, int type = 0){
  glmmrType model(xp,static_cast<Type>(type));
  auto functor = overloaded {
    [](int) {  return returnType(0);}, 
    [](auto ptr){return returnType(ptr->model.linear_predictor.P());}
  };
  auto S = std::visit(functor,model.ptr);
  return wrap(std::get<int>(S));
}
  • Fixed and improved formula parsing. Non-linear formulas had several small bugs which led to either incorrect calculations or crashes in some cases and also only accepted integer numbers. The improved parsing fixes these bugs and allows for any doubles to be used. In formulae any data name is automatically multiplied by a parameter unless it is wrapped in brackets, e.g. 2^x will parse as pow(2,b_x*x) and 2^(x) will be pow(2,x). An example complex spatial model with non-linear functional form used in a linked study is:
model <- Model$new(
  ~ b_eff*((1-(0.5*((b_del/d)^100+1)^(-0.01*b_k)))^b_v) + (1|nngp_fexp(x,y)),
  data=df,
  covariance = c(0.5,0.5),
  mean = c(0.5,0.5,0.5,1,3),
  family = gaussian()
)
  • Instructions for calculations have moved to using an enum class to massively improve the readability of the code. For example, instructions now read as {PushData, PushParameter, Multiply, Add} rather than {0,2,5,3}. The R Model class now includes a function calculator_instructions() to print the list of instructions to the console to help understand specification and parsing of non-linear functions.
  • Two optional flags have been added to the general.h file. Compiling with #define ENABLE_DEBUG will include a large number of debugging steps, currently this is mostly only useful when building for R as the debug prints to the R console - this will be updated for future releases. Using #define R_BUILD brings in Rcpp and adds R specific printing and output.
  • The initialiser for the R6 Model class now accepts just a vector of parameters for the covariance and mean arguments as this was the most common use case. For example, one can specify a model as
mod <- Model$new(
  ~ (1|fexp(x,y)),
  data = expand.grid(x = seq(-1,1,length.out = 25),
                      y = seq(-1,1,length.out = 25)),
  covariance = c(0.5,1),
  mean = c(0),
  family = gaussian()
)
  • Upper and lower bounds can optionally be set on the fixed effect parameters for the MCML and Laplace approximation model fitting.
  • There is now a function Model__set_bobyqa_control() that will set the BOBYQA control parameters npt rho and rhobeg. This is not exposed to the user in this package (although it is used in rts2)
  • Sparse matrix functions and operators have been moved out of this package and into the sparseChol package (v0.2.2)
  • Compilation now requires C++20
  • The R Model class member function fitted now includes an option sample=TRUE to generate fitted values by resampling from the fixed effect parameter sampling distribution.
  • The R Model class now overwrites the pointer in its member Covariance class with itself. Previously the member covariance object contained a pointer to a separate covariance class object and so doubled the memory requirement. The covariance class still initially generates it own class, which will be improved in future versions.
  • An error in the predict function has been fixed that caused a crash for some models.
  • A non-user exposed function is added to calculate the Hessian matrix numerically Model__hessian_numerical(). It is slow and not required here but may be useful for derived packages and functions.
  • A covariance only model with no intercept can now be specified as -1+(1|f(x)) previously this caused an error.