Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 2.4.0
Date: 2025-04-17 13:57:56 UTC
SHA: 9fa3109a41a9bd0ca095a30527ca34ba233c1e34
Date: 2025-06-17 20:25:38 UTC
SHA: 32dc9e0e856f599cdf2dab33ac994973fadb5c2f
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Imports:
parallel,
tidyr,
dplyr,
ggplot2
ggplot2,
stringr
Suggests:
testthat,
bookdown,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ S3method(plot,gg_variable)
S3method(plot,gg_vimp)
export(calc_auc)
export(calc_roc)
export(df_partial)
export(df_partialpro)
export(gg_error)
export(gg_error.randomForest)
export(gg_error.randomForest.formula)
Expand All @@ -35,6 +37,7 @@ export(kaplan)
export(nelson)
export(quantile_pts)
export(r_data_types)
export(varpro_feature_name)
importFrom(dplyr,across)
importFrom(dplyr,mutate)
importFrom(dplyr,n_distinct)
Expand All @@ -53,6 +56,7 @@ importFrom(stats,predict)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,xtabs)
importFrom(stringr,str_sub)
importFrom(survival,Surv)
importFrom(survival,strata)
importFrom(survival,survfit)
Expand Down
58 changes: 58 additions & 0 deletions R/gg_partial_df.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
##=============================================================================
#' Split partial lots into continuous or categorical datasets
#' @param part_dta partial plot data from \code{rfsrc::plot.variable}
#' @param nvars how many of the partial plot variables to calculate
#' @param cat_limit Categorical features are build when there are fewer than

Check warning on line 5 in R/gg_partial_df.R

View workflow job for this annotation

GitHub Actions / lint

file=R/gg_partial_df.R,line=5,col=77,[trailing_whitespace_linter] Remove trailing whitespace.
#' cat_limit unique features.
#' @param name a label name applied to all features. Useful when combining

Check warning on line 7 in R/gg_partial_df.R

View workflow job for this annotation

GitHub Actions / lint

file=R/gg_partial_df.R,line=7,col=75,[trailing_whitespace_linter] Remove trailing whitespace.
#' multiple partial plot objects in figures.
#'

Check warning on line 9 in R/gg_partial_df.R

View workflow job for this annotation

GitHub Actions / lint

file=R/gg_partial_df.R,line=9,col=3,[trailing_whitespace_linter] Remove trailing whitespace.
#' @export
df_partial = function(part_dta, nvars = NULL, cat_limit = 10, name=NULL) {

Check warning on line 11 in R/gg_partial_df.R

View workflow job for this annotation

GitHub Actions / lint

file=R/gg_partial_df.R,line=11,col=12,[assignment_linter] Use one of <-, <<- for assignment, not =.
## Prepare the partial dependencies data for panel plots
if (is.null(nvars)) {
nvars = length(part_dta$plotthis)

Check warning on line 14 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L13-L14

Added lines #L13 - L14 were not covered by tests
}

cont_list = list()
cat_list = list()
for (feature in seq(nvars)) {

Check warning on line 19 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L17-L19

Added lines #L17 - L19 were not covered by tests
## Format any continuous features (those with fewer than cat_limit unique values)
if (length(unique(part_dta$plotthis[[feature]]$x)) > cat_limit) {
plt.df = as.data.frame(
cbind(
x = part_dta$plotthis[[feature]]$x,
yhat = part_dta$plotthis[[feature]]$yhat
)
)
plt.df$name = names(part_dta$plotthis)[[feature]]

Check warning on line 28 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L21-L28

Added lines #L21 - L28 were not covered by tests

cont_list[[feature]] <- plt.df

Check warning on line 30 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L30

Added line #L30 was not covered by tests
} else{
## Categorical features

## Though VarPro works with logical or continuous only. Factors are
## one hot encoded internal to the varPro call.
plt.df = as.data.frame(
cbind(
x = factor(part_dta$plotthis[[feature]]$x),
yhat = part_dta$plotthis[[feature]]$yhat
)
)
plt.df$name = names(part_dta$plotthis)[[feature]]

Check warning on line 42 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L36-L42

Added lines #L36 - L42 were not covered by tests

cat_list[[feature]] <- plt.df

Check warning on line 44 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L44

Added line #L44 was not covered by tests
}
}
continuous = dplyr::bind_rows(cont_list)
categorical = dplyr::bind_rows(cat_list)

Check warning on line 48 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L47-L48

Added lines #L47 - L48 were not covered by tests

if(!is.na(name)){
continuous$model <- categorical$model <- name

Check warning on line 51 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L50-L51

Added lines #L50 - L51 were not covered by tests
}

return(list(
continuous = continuous,
categorical = categorical
))

Check warning on line 57 in R/gg_partial_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partial_df.R#L54-L57

Added lines #L54 - L57 were not covered by tests
}
79 changes: 79 additions & 0 deletions R/gg_partialpro_df.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
##=============================================================================
##=============================================================================
#' Split partial lots into continuous or categorical datasets
#' @param part_dta partial plot data from \code{rfsrc::plot.variable}
#' @param nvars how many of the partial plot variables to calculate
#' @param cat_limit Categorical features are build when there are fewer than
#' cat_limit unique features.
#' @param name a label name applied to all features. Useful when combining
#' multiple partial plot objects in figures.
#'
#' @export
#'
df_partialpro = function(part_dta, nvars = NULL, cat_limit=12, name=NULL) {
## Prepare the partial pro dependencies data for panel plots
if (is.null(nvars)) {
nvars = length(part_dta)

Check warning on line 16 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L15-L16

Added lines #L15 - L16 were not covered by tests
}

cont_list = list()
cat_list = list()
for (feature in seq(nvars)) {

Check warning on line 21 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L19-L21

Added lines #L19 - L21 were not covered by tests
## Format any continuous features (those with fewer than 10 unique values)
if (length(part_dta[[feature]]$xvirtual) > cat_limit) {
plt.df = as.data.frame(
cbind(
variable = part_dta[[feature]]$xvirtual,
parametric = colMeans(part_dta[[feature]]$yhat.par, na.rm =
TRUE),
nonparametric = colMeans(part_dta[[feature]]$yhat.nonpar, na.rm =
TRUE),
causal = colMeans(part_dta[[feature]]$yhat.causal, na.rm =
TRUE)
)
)
plt.df$name = names(part_dta)[[feature]]

Check warning on line 35 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L23-L35

Added lines #L23 - L35 were not covered by tests

cont_list[[feature]] <- plt.df

Check warning on line 37 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L37

Added line #L37 was not covered by tests
} else{
## Categorical features

## Though VarPro works with logical or continuous only. Factors are
## one hot encoded internal to the varPro call.
cat_feat = list()

Check warning on line 43 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L43

Added line #L43 was not covered by tests
## Each yhat has at least 2 columns, for logical values...
for (ind in seq(length(unique(part_dta[[feature]]$xorg)))) {
cat_feat[[ind]] = as.data.frame(
cbind(
parametric = part_dta[[feature]]$yhat.par[, ind],
nonparametric = part_dta[[feature]]$yhat.nonpar[, ind],
causal = part_dta[[feature]]$yhat.causal[, ind]
)
)
cat_feat[[ind]]$variable <-
unique(part_dta[[feature]]$xorg)[ind]
if (ind == 1) {
plt.df <- cat_feat[[ind]]

Check warning on line 56 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L45-L56

Added lines #L45 - L56 were not covered by tests
} else{
plt.df <- dplyr::bind_rows(plt.df, cat_feat[[ind]])

Check warning on line 58 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L58

Added line #L58 was not covered by tests
}
}

plt.df$name = names(part_dta)[[feature]]

Check warning on line 62 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L62

Added line #L62 was not covered by tests

cat_list[[feature]] <- plt.df

Check warning on line 64 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L64

Added line #L64 was not covered by tests
}
}

continuous = dplyr::bind_rows(cont_list)
categorical = dplyr::bind_rows(cat_list)

Check warning on line 69 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L68-L69

Added lines #L68 - L69 were not covered by tests

if(!is.na(name)){
continuous$model <- categorical$model <- name

Check warning on line 72 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L71-L72

Added lines #L71 - L72 were not covered by tests
}

return(list(
continuous = continuous,
categorical = categorical
))

Check warning on line 78 in R/gg_partialpro_df.R

View check run for this annotation

Codecov / codecov/patch

R/gg_partialpro_df.R#L75-L78

Added lines #L75 - L78 were not covered by tests
}
23 changes: 23 additions & 0 deletions R/varpro_feature_names.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

##=============================================================================
#' varpro one hot encodes features, so we need to get the "raw"
#' original variable names. This loops through the variable names
#' not in the original dataset, and cuts one character off the end
#' until we find the variable name in the original data.
#'
#' @param varpro_names vector of names output from varpro analysis
#' @param dataset the dataset used for varpro input.
#'
#' @importFrom stringr str_sub
#' @export
varpro_feature_name <- function(varpro_names, dataset) {
inc_set <- varpro_names[which(varpro_names %in% colnames(dataset))]
one_set <- varpro_names[which(!varpro_names %in% colnames(dataset))]
while (length(one_set) > 0) {
orig <- unlist(lapply(one_set, stringr::str_sub, 1,-2))
inc_set <-
union(inc_set, orig[which(orig %in% colnames(dataset))])
one_set <- orig[which(!orig %in% colnames(dataset))]
}
return(inc_set)

Check warning on line 22 in R/varpro_feature_names.R

View check run for this annotation

Codecov / codecov/patch

R/varpro_feature_names.R#L14-L22

Added lines #L14 - L22 were not covered by tests
}
22 changes: 22 additions & 0 deletions man/df_partial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/df_partialpro.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/varpro_feature_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading