Skip to content

Commit

Permalink
fix factor level ordering with >10 factors in trend_formula components
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed May 23, 2024
1 parent 9ced215 commit 78292a2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion R/get_linear_predictors.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ trend_Xp_matrix = function(newdata, trend_map, series = 'all',
trend_indicators[i] <- trend_map$trend[which(as.character(trend_map$series) ==
as.character(trend_test$series[i]))]
}
trend_indicators <- as.factor(paste0('trend', trend_indicators))
trend_indicators <- factor(paste0('trend', trend_indicators),
levels = paste0('trend',
unique(trend_map$trend)))
trend_test$series <- trend_indicators
trend_test$y <- NULL

Expand Down
4 changes: 3 additions & 1 deletion R/marginaleffects.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ get_data.mvgam = function (x, source = "environment", verbose = TRUE, ...) {
trend_indicators[i] <- x$trend_map$trend[which(x$trend_map$series ==
orig_dat$series[i])]
}
trend_indicators <- as.factor(paste0('trend', trend_indicators))
trend_indicators <- factor(paste0('trend', trend_indicators),
levels = paste0('trend',
unique(x$trend_map$trend)))

# Trend-level data, before any slicing that took place
trend_level_data <- data.frame(trend_series = trend_indicators,
Expand Down
2 changes: 1 addition & 1 deletion R/residuals.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ residuals.mvgam <- function(object,
time = object$obs_data$index..time..index)

series_numeric <- as.numeric(orig_order$series)
time_numeric <- orig_order$time
time_numeric <- match(orig_order$time, unique(orig_order$time))

# Build a matrix to return residuals in this order
resid_matrix <- matrix(NA, nrow = NROW(orig_order),
Expand Down
Binary file modified src/mvgam.dll
Binary file not shown.

0 comments on commit 78292a2

Please sign in to comment.