Skip to content

prais support #213

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

Merged
merged 2 commits into from
Jan 3, 2025
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Enhances:
ordinal,
pglm,
plm (>= 2.4.1),
prais (>= 1.1.3),
relevent,
remify (>= 3.2.6),
remstats (>= 3.2.2),
Expand All @@ -78,4 +79,4 @@ Enhances:
SystemRequirements: pandoc (>= 1.12.3) suggested for using wordreg function; LaTeX packages tikz, booktabs, dcolumn, rotating, thumbpdf, longtable, paralist for the vignette
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
71 changes: 71 additions & 0 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -6503,6 +6503,77 @@ setMethod("extract", signature = className("polr", "MASS"),
definition = extract.polr)


# -- extract.prais (prais) -----------------------------------------------------

#' @noRd
extract.prais <- function(model,
include.rsquared = TRUE,
include.adjrs = TRUE,
include.nobs = TRUE,
...) {
s <- summary(model, ...)

rho <- mean(s$rho[nrow(s$rho), ])

coefficient.names <- c(rownames(coef(s)), "rho")
coefficients <- c(coef(s)[, 1], rho)
standard.errors <- c(coef(s)[, 2], NA_real_)
significance <- c(coef(s)[, 4], NA_real_)

rs <- s$r.squared
adj <- s$adj.r.squared
n <- length(model$residuals)

gof <- numeric()
gof.names <- character()
gof.decimal <- logical()
if (include.rsquared == TRUE) {
gof <- c(gof, rs)
gof.names <- c(gof.names, "R$^2$")
gof.decimal <- c(gof.decimal, TRUE)
}
if (include.adjrs == TRUE) {
gof <- c(gof, adj)
gof.names <- c(gof.names, "Adj. R$^2$")
gof.decimal <- c(gof.decimal, TRUE)
}
if (include.nobs == TRUE) {
gof <- c(gof, n)
gof.names <- c(gof.names, "Num. obs.")
gof.decimal <- c(gof.decimal, FALSE)
}

tr <- createTexreg(
coef.names = coefficient.names,
coef = coefficients,
se = standard.errors,
pvalues = significance,
gof.names = gof.names,
gof = gof,
gof.decimal = gof.decimal
)
return(tr)
}

#' \code{\link{extract}} method for \code{prais} objects
#'
#' \code{\link{extract}} method for \code{prais} objects created by the
#' \code{\link[prais]{prais_winsten}} function in the \pkg{prais} package.
#'
#' @param model A statistical model object.
#' @param include.rsquared Report R^2 in the GOF block?
#' @param include.adjrs Report adjusted R^2 in the GOF block?
#' @param include.nobs Report the number of observations in the GOF block?
#' @param ... Custom parameters, which are handed over to subroutines, in this
#' case to the \code{summary} method for the object.
#'
#' @method extract prais
#' @aliases extract.prais
#' @export
setMethod("extract", signature = className("prais", "prais"),
definition = extract.prais)


# -- extract.rem.dyad (relevent) -----------------------------------------------

# extension for rem.dyad objects (relevent package)
Expand Down
31 changes: 31 additions & 0 deletions man/extract-prais-method.Rd

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

21 changes: 21 additions & 0 deletions tests/testthat/test-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,27 @@ test_that("extract pcce objects from the plm package", {
expect_equivalent(which([email protected]), 1:3)
})

# prais (prais) ----
test_that("extract prais objects from the prais package", {
testthat::skip_on_cran()
skip_if_not_installed("prais", minimum_version = "1.1.3")
set.seed(12345)
data("barium", package = "prais")
pwmod <- prais::prais_winsten(lchnimp ~ lchempi + lgas + lrtwex + befile6 + affile6 + afdec6, data = barium, index = "t")

tr <- extract(pwmod)
expect_length([email protected], 8)
expect_length(tr@coef, 8)
expect_length(tr@se, 8)
expect_length(tr@pvalues, 8)
expect_length([email protected], 0)
expect_length([email protected], 0)
expect_length(tr@gof, 3)
expect_length([email protected], 3)
expect_length([email protected], 3)
expect_equivalent(which([email protected]), 1:2)
})

# remstimate (remstimate) ----
test_that("extract remstimate objects from the remstimate package", {
testthat::skip_on_cran()
Expand Down
Loading