Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gt output for marginal covariance model #79

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions R/PrestoGP_Model.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,91 @@
}
)


#' summary table for PrestoGP models
#'
#' This method prints a summary of a PrestoGP model and its parameters using gt package
#'
#' @param object The PrestoGP model object
#'
#' @seealso \code{\link{PrestoGPModel-class}}, \code{\link{prestogp_fit}}
#'
#' @export
#'
#' @examples
#' data(soil)
#' soil <- soil[!is.na(soil[,5]),] # remove rows with NA's
#' y <- soil[,4] # predict moisture content
#' X <- as.matrix(soil[,5:9])
#' locs <- as.matrix(soil[,1:2])
#'
#' soil.vm <- new("VecchiaModel", n_neighbors = 10)
#' soil.vm <- prestogp_fit(soil.vm, y, X, locs)
#' show(soil.vm)

setMethod(
"summary", "PrestoGPModel",
function(object) {
theta_mdl <- get_theta(object)
beta_mdl <- get_beta(object)

Check warning on line 305 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=305,col=5,[object_usage_linter] local variable 'beta_mdl' assigned but may not be used



# Extract the marginal model parameters

Check warning on line 309 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=309,col=0,[indentation_linter] Indentation should be 4 spaces but is 0 spaces.
sigma <- theta_mdl$sigma
smoothness <- theta_mdl$smoothness
nuggets <- theta_mdl$nuggets
names(sigma) <- names(smoothness) <- names(nuggets) <- names(theta_mdl$sigma)

# Scales

Check warning on line 315 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=315,col=0,[indentation_linter] Indentation should be 4 spaces but is 0 spaces.
scale_dims <- length(unique(object@scaling))
scale_df <- data.frame(theta_mdl$scale, id = rep(1:scale_dims, each = length(sigma)))
scales <- scale_df%>%

Check warning on line 318 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=318,col=19,[infix_spaces_linter] Put spaces around all infix operators.
group_by(id) %>%

Check warning on line 319 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=319,col=3,[object_usage_linter] no visible global function definition for 'group_by'

Check warning on line 319 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=319,col=12,[object_usage_linter] no visible binding for global variable 'id'
group_split(.keep = FALSE)

Check warning on line 320 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=320,col=3,[object_usage_linter] no visible global function definition for 'group_split'

Check warning on line 320 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=320,col=29,[trailing_whitespace_linter] Trailing whitespace is superfluous.




# Construct model equations dynamically

Check warning on line 325 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=325,col=0,[indentation_linter] Indentation should be 4 spaces but is 0 spaces.
model_equations <- sapply(seq_along(sigma), function(i) {

Check warning on line 326 in R/PrestoGP_Model.R

View workflow job for this annotation

GitHub Actions / lint

file=R/PrestoGP_Model.R,line=326,col=1,[object_usage_linter] local variable 'model_equations' assigned but may not be used
glue(
"Cᵢᵢ(h) = σᵢᵢ² × M(h | {round(smoothness[i], 2)},[{paste(round(scales[[i]], 2), collapse = ', ')}]) + {round(nuggets[i]^2,4)}"
)
})

# Create the table
marginal_df <- data.frame(
Variable = names(sigma),
Sigma2 = sigma^2, # Avoid special characters
Smoothness = smoothness,
Nugget2 = nuggets^2, # Avoid special characters
Scales = sapply(scales, function(x) paste(round(x, 2), collapse = ", "))
)

# Render as a gt table
marginal_df %>%
gt() %>%
cols_label(
Variable = "Variable",
Sigma2 = "Marginal Variance (σᵢᵢ²)", # Properly labeled
Smoothness = "Smoothness (νᵢᵢ)",
Nugget2 = "nugget (τ²)",
Scales = "scales (α)"
) %>%
fmt_number(
columns = c(Sigma2, Smoothness, Nugget2, Scales),
decimals = 4 # Show 3 significant digits
) |>
tab_header(
title = "Marginal Models for Each Variable",
subtitle = "Cᵢᵢ(h) = σᵢᵢ² × M(h | νᵢᵢ, α)"
)


}
)

#' Extract the Matern (theta) parameters from a PrestoGP model.
#'
#' This method extracts a list containing the Matern variance/covariance
Expand Down
Loading