diff --git a/NAMESPACE b/NAMESPACE index aa991eecff2dec62c0d21d9bc95cff707eb7cc4a..6fa724cd540b262d1616e0650f2c313747256f1b 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 d885e12a7e483d616a84ff94972dbcf06c1fe951..eac46e934eb91909d35e2e7c02501bf2dc2db80e 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 984d8739f897d45088ab7d106cda934bada012c4..2bb6b35c57e2d5962b245e3f556bf3af08aaeadd 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 f6fab12afcc4922f728513284ee528e82452d780..083b810a875354ce8f8e085ffc1183bb16bd96de 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 0000000000000000000000000000000000000000..74e88a2f00c363fbb0af752a68a6f3f2645df85d --- /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 0000000000000000000000000000000000000000..bca1c6e7cfc2fd707d244eaa4ecf774be35271f0 --- /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 0000000000000000000000000000000000000000..5c7a497ad63b32f47908cd23c1e4d9a4e2005288 --- /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))