From 219df790f5172f08a1506f22c1714a0a5cd6c9f3 Mon Sep 17 00:00:00 2001 From: Julian Sagebiel <julian.sagebiel@idiv.de> Date: Mon, 3 Jun 2024 19:18:14 +0200 Subject: [PATCH] added exported functions subcoef and remGOF --- NAMESPACE | 2 ++ R/quicktexregapollo.R | 2 +- R/remGOF.R | 18 +++++++++++++++++ R/subcoef.R | 22 ++++++++++++++++++++- man/remGOF.Rd | 30 +++++++++++++++++++++++++++++ man/subcoef.Rd | 33 ++++++++++++++++++++++++++++++++ tests/manual-tests/remGOF-test.R | 30 +++++++++++++++++++++++++++++ 7 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 man/remGOF.Rd create mode 100644 man/subcoef.Rd create mode 100644 tests/manual-tests/remGOF-test.R diff --git a/NAMESPACE b/NAMESPACE index aa991ee..6fa724c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,4 +3,6 @@ export("%>%") export(createSets) export(quicktexregapollo) +export(remGOF) +export(subcoef) importFrom(magrittr,"%>%") diff --git a/R/quicktexregapollo.R b/R/quicktexregapollo.R index d885e12..eac46e9 100644 --- a/R/quicktexregapollo.R +++ b/R/quicktexregapollo.R @@ -26,7 +26,7 @@ quicktexregapollo <- function(model = model, wtpest = NULL, se="rob") { stop(" It seems you did not do bootstrapping. Thus, I cannot report bootstrapped se. The 'model' object must contain an element named 'bootse' when 'se' is 'bs'.") } - browser() + modelOutput_settings = list(printPVal=T) if (is.null(wtpest)) { diff --git a/R/remGOF.R b/R/remGOF.R index 984d873..2bb6b35 100644 --- a/R/remGOF.R +++ b/R/remGOF.R @@ -1,3 +1,21 @@ +#' Remove unnecessary statistics from Table for TexReg +#' +#' @param models the models you want to delete the GOF statistics +#' +#' @return a list with the same models as in models but without GOF statistics +#' @export +#' +#' @examples { +#' est_model <- readRDS(system.file("extdata", "mixlogitInt_bootstrap.RDS", package = "choiceTools")) +#' ## make full model in one column using texreg +#' full_model <- quicktexregapollo(est_model, se="normal") +#' texreg::screenreg(full_model) +#' ## split the model to different columns, e.g. for mean, sd, sample_interactions +#' splitmodels <- purrr::map(c("mean_","sd_" , paste0("_s",c(2:6)) ) ,subcoef,full_model) +#' texreg::screenreg(splitmodels) +#' ## the same, but make sure gof statistics are shown only once +#' texreg::screenreg(c(splitmodels[[1]],remGOF(splitmodels[2:7] ) ) ) +#' } remGOF<- function(models){ gof<- function(m){ diff --git a/R/subcoef.R b/R/subcoef.R index f6fab12..083b810 100644 --- a/R/subcoef.R +++ b/R/subcoef.R @@ -1,5 +1,25 @@ -# function to split model into different columns for texreg + +#' Title function to split model into different columns for texreg +#' +#' @param condition The stub that is common for all parameters you want to split. For example 'mean' +#' @param mname The name of the model you want to split +#' +#' @return a new texreg object with only the selected column (for example the model output with only the mean parameters) +#' @export +#' +#' @examples { +#' est_model <- readRDS(system.file("extdata", "mixlogitInt_bootstrap.RDS", package = "choiceTools")) +#' ## make full model in one column using texreg +#' full_model <- quicktexregapollo(est_model, se="normal") +#' texreg::screenreg(full_model) +#' ## split the model to different columns, e.g. for mean, sd, sample_interactions +#' splitmodels <- purrr::map(c("mean_","sd_" , paste0("_s",c(2:6)) ) ,subcoef,full_model) +#' texreg::screenreg(splitmodels) +#' ## the same, but make sure gof statistics are shown only once +#' texreg::screenreg(c(splitmodels[[1]],remGOF(splitmodels[2:7] ) ) ) +#' +#' } subcoef <- function(condition, mname){ sub <- grep(condition,methods::slot(mname,"coef.names")) diff --git a/man/remGOF.Rd b/man/remGOF.Rd new file mode 100644 index 0000000..74e88a2 --- /dev/null +++ b/man/remGOF.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/remGOF.R +\name{remGOF} +\alias{remGOF} +\title{Remove unnecessary statistics from Table for TexReg} +\usage{ +remGOF(models) +} +\arguments{ +\item{models}{the models you want to delete the GOF statistics} +} +\value{ +a list with the same models as in models but without GOF statistics +} +\description{ +Remove unnecessary statistics from Table for TexReg +} +\examples{ +{ +est_model <- readRDS(system.file("extdata", "mixlogitInt_bootstrap.RDS", package = "choiceTools")) +## make full model in one column using texreg +full_model <- quicktexregapollo(est_model, se="normal") +texreg::screenreg(full_model) +## split the model to different columns, e.g. for mean, sd, sample_interactions +splitmodels <- purrr::map(c("mean_","sd_" , paste0("_s",c(2:6)) ) ,subcoef,full_model) +texreg::screenreg(splitmodels) +## the same, but make sure gof statistics are shown only once +texreg::screenreg(c(splitmodels[[1]],remGOF(splitmodels[2:7] ) ) ) +} +} diff --git a/man/subcoef.Rd b/man/subcoef.Rd new file mode 100644 index 0000000..bca1c6e --- /dev/null +++ b/man/subcoef.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/subcoef.R +\name{subcoef} +\alias{subcoef} +\title{Title function to split model into different columns for texreg} +\usage{ +subcoef(condition, mname) +} +\arguments{ +\item{condition}{The stub that is common for all parameters you want to split. For example 'mean'} + +\item{mname}{The name of the model you want to split} +} +\value{ +a new texreg object with only the selected column (for example the model output with only the mean parameters) +} +\description{ +Title function to split model into different columns for texreg +} +\examples{ +{ +est_model <- readRDS(system.file("extdata", "mixlogitInt_bootstrap.RDS", package = "choiceTools")) +## make full model in one column using texreg +full_model <- quicktexregapollo(est_model, se="normal") +texreg::screenreg(full_model) +## split the model to different columns, e.g. for mean, sd, sample_interactions +splitmodels <- purrr::map(c("mean_","sd_" , paste0("_s",c(2:6)) ) ,subcoef,full_model) +texreg::screenreg(splitmodels) +## the same, but make sure gof statistics are shown only once +texreg::screenreg(c(splitmodels[[1]],remGOF(splitmodels[2:7] ) ) ) + +} +} diff --git a/tests/manual-tests/remGOF-test.R b/tests/manual-tests/remGOF-test.R new file mode 100644 index 0000000..5c7a497 --- /dev/null +++ b/tests/manual-tests/remGOF-test.R @@ -0,0 +1,30 @@ + +rm(list = ls()) +devtools::load_all() + + + +est_model <- readRDS(system.file("extdata", "mixlogitInt_bootstrap.RDS", package = "choiceTools")) + + + + + +## make full model in one column using texreg + +full_model <- quicktexregapollo(est_model, se="normal") + +texreg::screenreg(full_model) + + +## split the model to different columns, e.g. for mean, sd, sample_interactions +splitmodels <- purrr::map(c("mean_","sd_" , paste0("_s",c(2:6)) ) ,subcoef,full_model) + +texreg::screenreg(splitmodels) + + +## the same, but make sure gof statistics are shown only once +texreg::screenreg(c(splitmodels[[1]],remGOF(splitmodels[2:7] ) ) ) + + +janitor::clean_names(apollo::apollo_modelOutput(est_model)) -- GitLab