Skip to content

Commit

Permalink
sfsfs
Browse files Browse the repository at this point in the history
  • Loading branch information
svmiller committed Jan 22, 2025
1 parent 66f78dc commit fc079e7
Show file tree
Hide file tree
Showing 64 changed files with 200 additions and 192 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# stevemisc 1.9.0

- `spp_test()` is a simulation-based approach to interpreting the Phillips-Perron test for unit root.
- `rewb_at()` is a convenience wrapper for `mean_at()`, `group_mean_center_at()`, and `center_at()`. It's useful for preparing data for a random effects, within-between (REWB) panel analysis.

# stevemisc 1.8.0

Expand Down
80 changes: 80 additions & 0 deletions R/at.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
#' two standard deviations and not one. The default prefix ("z") can be
#' changed by way of an argument in the function.
#'
#' \code{rewb_at} is a wrapper for routines done by \code{mean_at},
#' \code{group_mean_center_at}, and \code{center_at} in this package. It
#' implicitly assumes the data are a panel and runs these three routines in order
#' to create so-called "between" and "within" variables for a "random effects,
#' within-between" analysis. Means are calculated based on available data, so
#' there is no `na` argument available in this function. The function will fail
#' in the presence of variables in the data matching those that this routine
#' wants to create.
#'
#' All functions, except for \code{lag_at}, will fail in the absence of a
#' character vector of a length of one. They are intended to work across multiple
#' columns instead of just one. If you are wanting to create one new variable,
Expand Down Expand Up @@ -95,6 +104,10 @@
#' is not applicable to \code{log_at} (why would it be) and is optional for all
#' functions except \code{group_mean_center_at}. \code{group_mean_center_at}
#' must have something specified for grouped mean-centering.
#' @param w_prefix Applicable only to \code{rewb_at}, but specifies prefix for
#' so-called "within" variables created by this procedure. Defaults to "w".
#' @param b_prefix Applicable only to \code{rewb_at}, but specifies prefix for
#' so-called "between" variables created by this procedure. Defaults to "b".
#'
#' @return The function returns a set of new vectors in a data frame after
#' performing relevant functions. The new vectors have distinct prefixes
Expand Down Expand Up @@ -218,6 +231,11 @@ group_mean_center_at <- function(data, x, mean_prefix = "mean",
stop("The use of a scoped helper verb like this requires more than one variable.")
}

# if(is.null(.by)) {
#
# warning("The absence of the .by argument means you're going to be subtracting a mean from itself. It's up to you if you want to do that. You probably didn't want that, but I did it anyway. I'm just bringing that to your attention.")
# }

# if(is.grouped_df(data) == FALSE) {
# warning("The absence of a grouping factor means you're going to be subtracting a mean from itself. It's up to you if you want to do that. You probably didn't want that, but I did it anyway. I'm just bringing that to your attention.")
# }
Expand Down Expand Up @@ -391,3 +409,65 @@ r2sd_at <- function(data, x, prefix = "z", na=TRUE, .by=NULL) {
return(data)

}


#' @rdname at
#' @export
#'
#'

rewb_at <- function(data, x, w_prefix = "w", b_prefix = "b", .by) {

if(is.null(.by)) {
stop("This procedure makes no sense in the absence of a grouping variable declared in the .by argument.")
}

by <- enquo(.by)

are_global_means_there <- paste0("mean_", x)

if (any(i <- are_global_means_there %in% colnames(data))) {
stop("There are global means with prefices of `mean_` in the data that this routine wants to create. It would be easier for you to remove those and proceed.")
}

are_bs_there <- paste0(b_prefix,"_", x)

if (any(i <- are_bs_there %in% colnames(data))) {
stop("The assumed group means that this routine wants to create appear to be in the data. It would be easier for you to remove those and proceed.")
}

are_ws_there <- paste0(w_prefix,"_", x)

if (any(i <- are_bs_there %in% colnames(data))) {
stop("The assumed 'within' variables that this routine wants to create appear to be in the data. It would be easier for you to remove those and proceed.")
}

if(length(x) == 1) {
stop("The use of a scoped helper verb like this requires more than one variable.")
}

mp <- paste0("mean_")
nvp <- paste0(b_prefix,"_{.col}")
nvp_check <- paste0(b_prefix, "_", x)


data %>%
# mean_at...
mutate(across(all_of(x),
~mean(., na.rm = TRUE),
.names = paste0("mean","_{.col}"))) %>%
# gmc_at...
mutate(across(all_of(x), ~
mean(., na.rm = TRUE) - get(str_c(mp, cur_column())), .names = nvp),
.by = !!by) %>%
# center at...
mutate(across(all_of(x),
~(.) - mean(., na.rm = TRUE),
.names = paste0(w_prefix,"_{.col}")),
.by = !!by) -> data

return(data)



}
4 changes: 2 additions & 2 deletions docs/404.html

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

12 changes: 6 additions & 6 deletions docs/authors.html

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

4 changes: 2 additions & 2 deletions docs/index.html

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

11 changes: 8 additions & 3 deletions docs/news/index.html

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

8 changes: 8 additions & 0 deletions docs/pkgdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,11 @@ async function searchFuse(query, callback) {
});
});
})(window.jQuery || window.$)

document.addEventListener('keydown', function(event) {
// Check if the pressed key is '/'
if (event.key === '/') {
event.preventDefault(); // Prevent any default action associated with the '/' key
document.getElementById('search-input').focus(); // Set focus to the search input
}
});
4 changes: 2 additions & 2 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pandoc: 3.1.1
pkgdown: 2.1.0
pkgdown: 2.1.1
pkgdown_sha: ~
articles: {}
last_built: 2024-08-22T14:30Z
last_built: 2025-01-22T18:13Z
urls:
reference: http://svmiller.com/reference
article: http://svmiller.com/articles
4 changes: 2 additions & 2 deletions docs/reference/at.html

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

Binary file modified docs/reference/binred_plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/reference/binred_plot.html

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

4 changes: 2 additions & 2 deletions docs/reference/carrec.html

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

4 changes: 2 additions & 2 deletions docs/reference/charitable_contributions.html

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

4 changes: 2 additions & 2 deletions docs/reference/cor2data.html

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

4 changes: 2 additions & 2 deletions docs/reference/corvectors.html

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

4 changes: 2 additions & 2 deletions docs/reference/db_lselect.html

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

4 changes: 2 additions & 2 deletions docs/reference/ess9_labelled.html

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

Loading

0 comments on commit fc079e7

Please sign in to comment.