Skip to content

Commit

Permalink
fixing some weird behavior with base R commands
Browse files Browse the repository at this point in the history
  • Loading branch information
michellepistner committed May 3, 2024
1 parent 006426c commit d4fe00d
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 194 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ export(alr)
export(alrInv)
export(alrInv_array)
export(alr_array)
export(as.list)
export(basset)
export(check_dims)
export(clr_array)
export(coef)
export(conjugateLinearModel)
export(create_default_ilr_base)
export(gather_array)
Expand Down Expand Up @@ -112,16 +110,13 @@ export(pibble_tidy_samples)
export(pibblefit)
export(ppc)
export(ppc_summary)
export(predict)
export(print)
export(random_pibble_init)
export(reapply_coord)
export(refit)
export(req)
export(sample_prior)
export(store_coord)
export(summarise_posterior)
export(summary)
export(to_alr)
export(to_clr)
export(to_ilr)
Expand Down
141 changes: 72 additions & 69 deletions R/fidofit_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ summary_check_precomputed <- function(m, pars){
}


#' Summarise pibblefit or orthusfit object and print posterior quantiles
#'
#' Default calculates median, mean, 50\% and 95\% credible interval
#'
#' @param object an object of class pibblefit or orthusfit
#' @param ... other objects to be passed to `summary.pibblefit` or `summary.orthusfit`
#' @return A list if class is `pibblefit` or `orthusfit`
#' @export
summary <- function(object, ...){
UseMethod("summary")
}
#' #' Summarise pibblefit or orthusfit object and print posterior quantiles
#' #'
#' #' Default calculates median, mean, 50\% and 95\% credible interval
#' #'
#' #' @param object an object of class pibblefit or orthusfit
#' #' @param ... other objects to be passed to `summary.pibblefit` or `summary.orthusfit`
#' #' @return A list if class is `pibblefit` or `orthusfit`
#' #' @export
#' summary <- function(object, ...){
#' UseMethod("summary")
#' }


#' Summarise pibblefit object and print posterior quantiles
Expand Down Expand Up @@ -285,20 +285,20 @@ summary.orthusfit <- function(object, pars=NULL, use_names=TRUE, as_factor=FALSE
}


#' Print dimensions and coordinate system information for an orthusfit or pibblefit object.
#'
#' @param x an object of class pibblefit or orthusfit
#' @param ... other arguments to pass to summary function
#' @return No direct value, but a print out
#' @export
#' @examples
#' sim <- pibble_sim()
#' fit <- pibble(sim$Y, sim$X)
#' print(fit)
#'
print <- function(x, ...){
UseMethod("print")
}
#' #' Print dimensions and coordinate system information for an orthusfit or pibblefit object.
#' #'
#' #' @param x an object of class pibblefit or orthusfit
#' #' @param ... other arguments to pass to summary function
#' #' @return No direct value, but a print out
#' #' @export
#' #' @examples
#' #' sim <- pibble_sim()
#' #' fit <- pibble(sim$Y, sim$X)
#' #' print(fit)
#' #'
#' print <- function(x, ...){
#' UseMethod("print")
#' }


#' Print dimensions and coordinate system information for pibblefit object.
Expand Down Expand Up @@ -403,22 +403,22 @@ print.orthusfit <- function(x, summary=FALSE, ...){
}


#' Return regression coefficients of pibblefit or orthusfit object

#'
#' @param object an object of class pibblefit or orthusfit
#' @param ... other options passed to coef.pibblefit or coef.orthusfit (see details)
#' @return Array of dimension (D-1) x Q x iter
#'
#' @export
#' @examples
#' sim <- pibble_sim()
#' fit <- pibble(sim$Y, sim$X)
#' coef(fit)
#'
coef <- function(object, ...){
UseMethod("coef")
}
#' #' Return regression coefficients of pibblefit or orthusfit object
#'
#' #'
#' #' @param object an object of class pibblefit or orthusfit
#' #' @param ... other options passed to coef.pibblefit or coef.orthusfit (see details)
#' #' @return Array of dimension (D-1) x Q x iter
#' #'
#' #' @export
#' #' @examples
#' #' sim <- pibble_sim()
#' #' fit <- pibble(sim$Y, sim$X)
#' #' coef(fit)
#' #'
#' coef <- function(object, ...){
#' UseMethod("coef")
#' }



Expand Down Expand Up @@ -476,16 +476,16 @@ coef.orthusfit <- function(object, ...){



#' Generic method to convert to list
#'
#' @param x An object of class pibblefit or orthusfit
#' @param ... Other objects to pass
#'
#' @return A list object
#' @export
as.list <- function(x, ...){
UseMethod("as.list")
}
#' #' Generic method to convert to list
#' #'
#' #' @param x An object of class pibblefit or orthusfit
#' #' @param ... Other objects to pass
#' #'
#' #' @return A list object
#' #' @export
#' as.list <- function(x, ...){
#' UseMethod("as.list")
#' }


#' Convert object of class pibblefit to a list
Expand Down Expand Up @@ -516,24 +516,24 @@ as.list.orthusfit <- function(x,...){



#' Predict response from new data
#'
#'
#' @param object An object of class pibblefit
#' @param ... Other objects to be passed to the `predict` function
#'
#' @return (if summary==FALSE) array D x N x iter; (if summary==TRUE)
#' tibble with calculated posterior summaries
#'
#' @export
#' @importFrom stats median predict runif
#' @examples
#' sim <- pibble_sim()
#' fit <- pibble(sim$Y, sim$X)
#' predict(fit)[,,1:2] # just show 2 samples
predict <- function(object, ...){
UseMethod("predict")
}
#' #' Predict response from new data
#' #'
#' #'
#' #' @param object An object of class pibblefit
#' #' @param ... Other objects to be passed to the `predict` function
#' #'
#' #' @return (if summary==FALSE) array D x N x iter; (if summary==TRUE)
#' #' tibble with calculated posterior summaries
#' #'
#' #' @export
#' #' @importFrom stats median predict runif
#' #' @examples
#' #' sim <- pibble_sim()
#' #' fit <- pibble(sim$Y, sim$X)
#' #' predict(fit)[,,1:2] # just show 2 samples
#' predict <- function(object, ...){
#' UseMethod("predict")
#' }



Expand Down Expand Up @@ -644,6 +644,9 @@ predict.pibblefit <- function(object, newdata=NULL, response="LambdaX", size=NUL
# Draw Eta
Eta <- array(0, dim=dim(LambdaX))
zEta <- array(rnorm((object$D-1)*nnew*iter), dim = dim(Eta))
if(is.null(object$Sigma)){
print("Sigma is needed to predict either Eta or Y.")
}
for (i in 1:iter){
Eta[,,i] <- LambdaX[,,i] + t(chol(object$Sigma[,,i]))%*%zEta[,,i]
}
Expand Down
Loading

0 comments on commit d4fe00d

Please sign in to comment.