From d1e6e854678333d357b2d1c202b1ebe120b4167a Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 Nov 2024 07:54:11 +0100 Subject: [PATCH] Support for `panelr::asym()` (#969) * Support for `panelr::asym()` Fixes #607 * fix formula * fixes * update readme * Update get_varcov.R --- DESCRIPTION | 2 +- NAMESPACE | 8 ++ NEWS.md | 2 + R/find_formula.R | 27 ++++ R/find_parameters_other.R | 18 +++ R/find_statistic.R | 1 + R/get_parameters_others.R | 17 +++ R/get_statistic.R | 16 +++ R/get_varcov.R | 10 ++ R/is_model.R | 4 +- R/is_model_supported.R | 7 +- R/link_function.R | 3 + R/link_inverse.R | 3 + R/model_info.R | 6 + README.md | 231 +++++++++++++++--------------- tests/testthat/test-panelr-asym.R | 129 +++++++++++++++++ 16 files changed, 363 insertions(+), 121 deletions(-) create mode 100644 tests/testthat/test-panelr-asym.R diff --git a/DESCRIPTION b/DESCRIPTION index b43d75dc5..c96200b09 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: insight Title: Easy Access to Model Information for Various Model Objects -Version: 0.99.0.14 +Version: 0.99.0.15 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NAMESPACE b/NAMESPACE index dcaaa1ba4..79bc9c69d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -89,6 +89,7 @@ S3method(find_formula,SemiParBIV) S3method(find_formula,afex_aov) S3method(find_formula,anova) S3method(find_formula,aovlist) +S3method(find_formula,asym) S3method(find_formula,averaging) S3method(find_formula,bamlss) S3method(find_formula,betamfx) @@ -199,6 +200,7 @@ S3method(find_parameters,aareg) S3method(find_parameters,afex_aov) S3method(find_parameters,anova.rms) S3method(find_parameters,aovlist) +S3method(find_parameters,asym) S3method(find_parameters,averaging) S3method(find_parameters,bamlss) S3method(find_parameters,bayesQR) @@ -620,6 +622,7 @@ S3method(get_parameters,aareg) S3method(get_parameters,afex_aov) S3method(get_parameters,aov) S3method(get_parameters,aovlist) +S3method(get_parameters,asym) S3method(get_parameters,averaging) S3method(get_parameters,bamlss) S3method(get_parameters,bayesQR) @@ -824,6 +827,7 @@ S3method(get_statistic,SemiParBIV) S3method(get_statistic,aareg) S3method(get_statistic,afex_aov) S3method(get_statistic,anova.rms) +S3method(get_statistic,asym) S3method(get_statistic,averaging) S3method(get_statistic,bayesx) S3method(get_statistic,betamfx) @@ -972,6 +976,7 @@ S3method(get_varcov,MixMod) S3method(get_varcov,Rchoice) S3method(get_varcov,afex_aov) S3method(get_varcov,aov) +S3method(get_varcov,asym) S3method(get_varcov,averaging) S3method(get_varcov,betamfx) S3method(get_varcov,betaor) @@ -1081,6 +1086,7 @@ S3method(link_function,RM) S3method(link_function,Rchoice) S3method(link_function,afex_aov) S3method(link_function,aovlist) +S3method(link_function,asym) S3method(link_function,averaging) S3method(link_function,bamlss) S3method(link_function,bayesx) @@ -1208,6 +1214,7 @@ S3method(link_inverse,RM) S3method(link_inverse,Rchoice) S3method(link_inverse,afex_aov) S3method(link_inverse,aovlist) +S3method(link_inverse,asym) S3method(link_inverse,averaging) S3method(link_inverse,bamlss) S3method(link_inverse,bayesx) @@ -1342,6 +1349,7 @@ S3method(model_info,aareg) S3method(model_info,afex_aov) S3method(model_info,anova) S3method(model_info,aovlist) +S3method(model_info,asym) S3method(model_info,averaging) S3method(model_info,bamlss) S3method(model_info,bayesQR) diff --git a/NEWS.md b/NEWS.md index b3fcf972f..4a93c1eb6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -43,6 +43,8 @@ * Added support for `coxph.panel` models. +* Added support for models of class `asym` (package *panelr*). + * Overhaul of documentation for the package-functions. ## Bug fix diff --git a/R/find_formula.R b/R/find_formula.R index b615ff359..f8a65b648 100644 --- a/R/find_formula.R +++ b/R/find_formula.R @@ -107,6 +107,33 @@ find_formula.default <- function(x, verbose = TRUE, ...) { } +#' @export +find_formula.asym <- function(x, verbose = TRUE, ...) { + modified_f <- safe_deparse(stats::formula(x)) + # limitation: we can't preserve "*" and ":" + modified_f <- gsub("*", "+", modified_f, fixed = TRUE) + modified_f <- gsub(":", "+", modified_f, fixed = TRUE) + # explanation: + # - gsub("\\+\\s*minus__[^\\+]+", "", input_string): + # This regular expression matches and removes any term that starts with + # + minus__ followed by any characters that are not a +. + # - gsub("\\s*\\+\\s*$", "", output_string): + # This removes any trailing plus sign and whitespace that might be left + # at the end of the string. + output_string <- gsub("\\+\\s*minus__[^\\+]+", "", modified_f) + output_string <- gsub("\\s*(\\+|\\*)\\s*$", "", output_string) # Remove trailing plus sign if any + # explanation: + # - gsub("lag_([a-zA-Z]+)_", "lag(\\1)", input_string): + # This regular expression matches the pattern "lag_", followed by one or + # more letters (captured in a group), followed by "_". It replaces this + # pattern with "lag(", the captured group, and ")". + output_string <- gsub("lag_([a-zA-Z]+)_", "lag(\\1)", output_string) + output_string <- gsub("plus__", "", output_string, fixed = TRUE) + f <- .safe(list(conditional = stats::as.formula(output_string))) + .find_formula_return(f, verbose = verbose) +} + + #' @export find_formula.list <- function(x, verbose = TRUE, ...) { if (object_has_names(x, "gam")) { diff --git a/R/find_parameters_other.R b/R/find_parameters_other.R index 7d6c7f283..438f790ea 100644 --- a/R/find_parameters_other.R +++ b/R/find_parameters_other.R @@ -256,3 +256,21 @@ find_parameters.coxph <- function(x, flatten = FALSE, ...) { out } } + + +#' @export +find_parameters.asym <- function(x, flatten = FALSE, ...) { + cf <- stats::coef(x) + + params <- names(cf) + params <- gsub("^plus__", "+", params) + params <- gsub("^minus__", "-", params) + + out <- list(conditional = params) + + if (flatten) { + unique(unlist(out, use.names = FALSE)) + } else { + out + } +} diff --git a/R/find_statistic.R b/R/find_statistic.R index b5eabaa4f..e8914d26d 100644 --- a/R/find_statistic.R +++ b/R/find_statistic.R @@ -91,6 +91,7 @@ find_statistic.default <- function(x, ...) { # t-value objects ---------------------------------------------------------- t.mods <- c( + "asym", "bayesx", "BBreg", "BBmm", "bcplm", "biglm", "bfsl", "blmerMod", "cch", "censReg", "complmrob", "cpglm", "cpglmm", "crq", "crqs", "drc", diff --git a/R/get_parameters_others.R b/R/get_parameters_others.R index 538b395df..5a33dac3e 100644 --- a/R/get_parameters_others.R +++ b/R/get_parameters_others.R @@ -433,3 +433,20 @@ get_parameters.coxph <- function(x, verbose = TRUE, ...) { text_remove_backticks(params) } + + +#' @export +get_parameters.asym <- function(x, verbose = TRUE, ...) { + cf <- stats::coef(x) + params <- data.frame( + Parameter = names(cf), + Estimate = unname(cf), + stringsAsFactors = FALSE, + row.names = NULL + ) + + params$Parameter <- gsub("^plus__", "+", params$Parameter) + params$Parameter <- gsub("^minus__", "-", params$Parameter) + + text_remove_backticks(params) +} diff --git a/R/get_statistic.R b/R/get_statistic.R index ae9e2e600..21ebaed12 100644 --- a/R/get_statistic.R +++ b/R/get_statistic.R @@ -194,6 +194,22 @@ get_statistic.merModList <- function(x, ...) { } +#' @export +get_statistic.asym <- function(x, ...) { + cftable <- summary(x)$coef_table + out <- data.frame( + Parameter = rownames(x$cftable), + Statistic = cftable[, "t val."], + stringsAsFactors = FALSE, + row.names = NULL + ) + + out <- text_remove_backticks(out) + attr(out, "statistic") <- find_statistic(x) + out +} + + #' @export get_statistic.afex_aov <- function(x, ...) { out <- data.frame( diff --git a/R/get_varcov.R b/R/get_varcov.R index d2d54ad8b..c2613a9bf 100644 --- a/R/get_varcov.R +++ b/R/get_varcov.R @@ -134,6 +134,16 @@ get_varcov.fixest <- function(x, } +#' @export +get_varcov.asym <- function(x, ...) { + out <- get_varcov.default(x, ...) + colnames(out) <- gsub("^plus__", "+", colnames(out)) + rownames(out) <- gsub("^plus__", "+", rownames(out)) + colnames(out) <- gsub("^minus__", "-", colnames(out)) + rownames(out) <- gsub("^minus__", "-", rownames(out)) + out +} + # mlm --------------------------------------------- diff --git a/R/is_model.R b/R/is_model.R index 19ee5cd85..28467341a 100644 --- a/R/is_model.R +++ b/R/is_model.R @@ -57,7 +57,7 @@ is_regression_model <- function(x) { # a -------------------- "aareg", "afex_aov", "AKP", "ancova", "anova", "Anova.mlm", - "anova.rms", "aov", "aovlist", "Arima", "averaging", + "anova.rms", "aov", "aovlist", "Arima", "averaging", "asym", # b -------------------- "bamlss", "bamlss.frame", "bayesGAM", "bayesmeta", "bayesx", @@ -81,7 +81,7 @@ is_regression_model <- function(x) { "eglm", "elm", "emmGrid", "emm_list", "epi.2by2", "ergm", # f -------------------- - "feglm", "feis", "felm", "fitdistr", "fixest", "flexmix", + "fdm", "feglm", "feis", "felm", "fitdistr", "fixest", "flexmix", "flexsurvreg", "flac", "flic", # g -------------------- diff --git a/R/is_model_supported.R b/R/is_model_supported.R index 74329c2ab..a7cd8fcba 100644 --- a/R/is_model_supported.R +++ b/R/is_model_supported.R @@ -44,8 +44,8 @@ supported_models <- function() { .supported_models_list <- function() { c( # a ---------------------------- - "aareg", "afex_aov", "aov", "aovlist", "AKP", "Anova.mlm", "anova.rms", - "Arima", "averaging", + "asym", "aareg", "afex_aov", "aov", "aovlist", "AKP", "Anova.mlm", + "anova.rms", "Arima", "averaging", # b ---------------------------- "bamlss", "bamlss.frame", "bayesx", "bayesQR", "BBmm", "BBreg", "bcplm", @@ -66,7 +66,8 @@ supported_models <- function() { "eglm", "elm", "epi.2by2", "ergm", "emmGrid", # f ---------------------------- - "feis", "felm", "feglm", "fitdistr", "fixest", "flexsurvreg", "flac", "flic", + "fdm", "feis", "felm", "feglm", "fitdistr", "fixest", "flexsurvreg", + "flac", "flic", # g ---------------------------- "gam", "Gam", "gamlss", "gamm", "gamm4", "garch", "gbm", "gee", "geeglm", diff --git a/R/link_function.R b/R/link_function.R index a696c6c98..ca06e49b7 100644 --- a/R/link_function.R +++ b/R/link_function.R @@ -78,6 +78,9 @@ link_function.lm <- function(x, ...) { .extract_generic_linkfun(x, "identity") } +#' @export +link_function.asym <- link_function.lm + #' @export link_function.phylolm <- link_function.lm diff --git a/R/link_inverse.R b/R/link_inverse.R index 44de28207..b6d3c3492 100644 --- a/R/link_inverse.R +++ b/R/link_inverse.R @@ -127,6 +127,9 @@ link_inverse.lm <- function(x, ...) { .extract_generic_linkinv(x, "identity") } +#' @export +link_inverse.asym <- link_inverse.lm + #' @export link_inverse.phylolm <- link_inverse.lm diff --git a/R/model_info.R b/R/model_info.R index b98ee6843..674cadcb9 100644 --- a/R/model_info.R +++ b/R/model_info.R @@ -145,6 +145,12 @@ model_info.anova <- function(x, verbose = TRUE, ...) { } +#' @export +model_info.asym <- function(x, verbose = TRUE, ...) { + .make_family(x, verbose = verbose, ...) +} + + #' @export model_info.mclogit <- function(x, verbose = TRUE, ...) { .make_family( diff --git a/README.md b/README.md index f8ba4836a..6abd44547 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ email or also file an issue. ## List of Supported Models by Class -Currently, about 236 model classes are supported. +Currently, about 238 model classes are supported. ``` r supported_models() @@ -289,120 +289,121 @@ supported_models() #> [3] "AKP" "Anova.mlm" #> [5] "anova.rms" "aov" #> [7] "aovlist" "Arima" -#> [9] "averaging" "bamlss" -#> [11] "bamlss.frame" "bayesQR" -#> [13] "bayesx" "BBmm" -#> [15] "BBreg" "bcplm" -#> [17] "betamfx" "betaor" -#> [19] "betareg" "BFBayesFactor" -#> [21] "bfsl" "BGGM" -#> [23] "bife" "bifeAPEs" -#> [25] "bigglm" "biglm" -#> [27] "blavaan" "blrm" -#> [29] "bracl" "brglm" -#> [31] "brmsfit" "brmultinom" -#> [33] "btergm" "censReg" -#> [35] "cgam" "cgamm" -#> [37] "cglm" "clm" -#> [39] "clm2" "clmm" -#> [41] "clmm2" "clogit" -#> [43] "coeftest" "complmrob" -#> [45] "confusionMatrix" "coxme" -#> [47] "coxph" "coxph.penal" -#> [49] "coxph_weightit" "coxr" -#> [51] "cpglm" "cpglmm" -#> [53] "crch" "crq" -#> [55] "crqs" "crr" -#> [57] "dep.effect" "DirichletRegModel" -#> [59] "draws" "drc" -#> [61] "eglm" "elm" -#> [63] "emmGrid" "epi.2by2" -#> [65] "ergm" "feglm" -#> [67] "feis" "felm" -#> [69] "fitdistr" "fixest" -#> [71] "flac" "flexsurvreg" -#> [73] "flic" "gam" -#> [75] "Gam" "gamlss" -#> [77] "gamm" "gamm4" -#> [79] "garch" "gbm" -#> [81] "gee" "geeglm" -#> [83] "ggcomparisons" "glht" -#> [85] "glimML" "glm" -#> [87] "Glm" "glm_weightit" -#> [89] "glmerMod" "glmgee" -#> [91] "glmm" "glmmadmb" -#> [93] "glmmPQL" "glmmTMB" -#> [95] "glmrob" "glmRob" -#> [97] "glmx" "gls" -#> [99] "gmnl" "hglm" -#> [101] "HLfit" "htest" -#> [103] "hurdle" "iv_robust" -#> [105] "ivFixed" "ivprobit" -#> [107] "ivreg" "lavaan" -#> [109] "lm" "lm_robust" -#> [111] "lme" "lmerMod" -#> [113] "lmerModLmerTest" "lmodel2" -#> [115] "lmrob" "lmRob" -#> [117] "logistf" "logitmfx" -#> [119] "logitor" "logitr" -#> [121] "LORgee" "lqm" -#> [123] "lqmm" "lrm" -#> [125] "manova" "MANOVA" -#> [127] "marginaleffects" "marginaleffects.summary" -#> [129] "margins" "maxLik" -#> [131] "mblogit" "mclogit" -#> [133] "mcmc" "mcmc.list" -#> [135] "MCMCglmm" "mcp1" -#> [137] "mcp12" "mcp2" -#> [139] "med1way" "mediate" -#> [141] "merMod" "merModList" -#> [143] "meta_bma" "meta_fixed" -#> [145] "meta_random" "metaplus" -#> [147] "mhurdle" "mipo" -#> [149] "mira" "mixed" -#> [151] "MixMod" "mixor" -#> [153] "mjoint" "mle" -#> [155] "mle2" "mlm" -#> [157] "mlogit" "mmclogit" -#> [159] "mmlogit" "mmrm" -#> [161] "mmrm_fit" "mmrm_tmb" -#> [163] "model_fit" "multinom" -#> [165] "multinom_weightit" "mvord" -#> [167] "negbinirr" "negbinmfx" -#> [169] "nestedLogit" "ols" -#> [171] "onesampb" "ordinal_weightit" -#> [173] "orm" "pgmm" -#> [175] "phyloglm" "phylolm" -#> [177] "plm" "PMCMR" -#> [179] "poissonirr" "poissonmfx" -#> [181] "polr" "probitmfx" -#> [183] "psm" "Rchoice" -#> [185] "ridgelm" "riskRegression" -#> [187] "rjags" "rlm" -#> [189] "rlmerMod" "RM" -#> [191] "rma" "rma.uni" -#> [193] "robmixglm" "robtab" -#> [195] "rq" "rqs" -#> [197] "rqss" "rvar" -#> [199] "Sarlm" "scam" -#> [201] "selection" "sem" -#> [203] "SemiParBIV" "semLm" -#> [205] "semLme" "seqanova.svyglm" -#> [207] "serp" "slm" -#> [209] "speedglm" "speedlm" -#> [211] "stanfit" "stanmvreg" -#> [213] "stanreg" "summary.lm" -#> [215] "survfit" "survreg" -#> [217] "svy_vglm" "svy2lme" -#> [219] "svychisq" "svyglm" -#> [221] "svyolr" "t1way" -#> [223] "tobit" "trimcibt" -#> [225] "truncreg" "vgam" -#> [227] "vglm" "wbgee" -#> [229] "wblm" "wbm" -#> [231] "wmcpAKP" "yuen" -#> [233] "yuend" "zcpglm" -#> [235] "zeroinfl" "zerotrunc" +#> [9] "asym" "averaging" +#> [11] "bamlss" "bamlss.frame" +#> [13] "bayesQR" "bayesx" +#> [15] "BBmm" "BBreg" +#> [17] "bcplm" "betamfx" +#> [19] "betaor" "betareg" +#> [21] "BFBayesFactor" "bfsl" +#> [23] "BGGM" "bife" +#> [25] "bifeAPEs" "bigglm" +#> [27] "biglm" "blavaan" +#> [29] "blrm" "bracl" +#> [31] "brglm" "brmsfit" +#> [33] "brmultinom" "btergm" +#> [35] "censReg" "cgam" +#> [37] "cgamm" "cglm" +#> [39] "clm" "clm2" +#> [41] "clmm" "clmm2" +#> [43] "clogit" "coeftest" +#> [45] "complmrob" "confusionMatrix" +#> [47] "coxme" "coxph" +#> [49] "coxph.penal" "coxph_weightit" +#> [51] "coxr" "cpglm" +#> [53] "cpglmm" "crch" +#> [55] "crq" "crqs" +#> [57] "crr" "dep.effect" +#> [59] "DirichletRegModel" "draws" +#> [61] "drc" "eglm" +#> [63] "elm" "emmGrid" +#> [65] "epi.2by2" "ergm" +#> [67] "fdm" "feglm" +#> [69] "feis" "felm" +#> [71] "fitdistr" "fixest" +#> [73] "flac" "flexsurvreg" +#> [75] "flic" "gam" +#> [77] "Gam" "gamlss" +#> [79] "gamm" "gamm4" +#> [81] "garch" "gbm" +#> [83] "gee" "geeglm" +#> [85] "ggcomparisons" "glht" +#> [87] "glimML" "glm" +#> [89] "Glm" "glm_weightit" +#> [91] "glmerMod" "glmgee" +#> [93] "glmm" "glmmadmb" +#> [95] "glmmPQL" "glmmTMB" +#> [97] "glmrob" "glmRob" +#> [99] "glmx" "gls" +#> [101] "gmnl" "hglm" +#> [103] "HLfit" "htest" +#> [105] "hurdle" "iv_robust" +#> [107] "ivFixed" "ivprobit" +#> [109] "ivreg" "lavaan" +#> [111] "lm" "lm_robust" +#> [113] "lme" "lmerMod" +#> [115] "lmerModLmerTest" "lmodel2" +#> [117] "lmrob" "lmRob" +#> [119] "logistf" "logitmfx" +#> [121] "logitor" "logitr" +#> [123] "LORgee" "lqm" +#> [125] "lqmm" "lrm" +#> [127] "manova" "MANOVA" +#> [129] "marginaleffects" "marginaleffects.summary" +#> [131] "margins" "maxLik" +#> [133] "mblogit" "mclogit" +#> [135] "mcmc" "mcmc.list" +#> [137] "MCMCglmm" "mcp1" +#> [139] "mcp12" "mcp2" +#> [141] "med1way" "mediate" +#> [143] "merMod" "merModList" +#> [145] "meta_bma" "meta_fixed" +#> [147] "meta_random" "metaplus" +#> [149] "mhurdle" "mipo" +#> [151] "mira" "mixed" +#> [153] "MixMod" "mixor" +#> [155] "mjoint" "mle" +#> [157] "mle2" "mlm" +#> [159] "mlogit" "mmclogit" +#> [161] "mmlogit" "mmrm" +#> [163] "mmrm_fit" "mmrm_tmb" +#> [165] "model_fit" "multinom" +#> [167] "multinom_weightit" "mvord" +#> [169] "negbinirr" "negbinmfx" +#> [171] "nestedLogit" "ols" +#> [173] "onesampb" "ordinal_weightit" +#> [175] "orm" "pgmm" +#> [177] "phyloglm" "phylolm" +#> [179] "plm" "PMCMR" +#> [181] "poissonirr" "poissonmfx" +#> [183] "polr" "probitmfx" +#> [185] "psm" "Rchoice" +#> [187] "ridgelm" "riskRegression" +#> [189] "rjags" "rlm" +#> [191] "rlmerMod" "RM" +#> [193] "rma" "rma.uni" +#> [195] "robmixglm" "robtab" +#> [197] "rq" "rqs" +#> [199] "rqss" "rvar" +#> [201] "Sarlm" "scam" +#> [203] "selection" "sem" +#> [205] "SemiParBIV" "semLm" +#> [207] "semLme" "seqanova.svyglm" +#> [209] "serp" "slm" +#> [211] "speedglm" "speedlm" +#> [213] "stanfit" "stanmvreg" +#> [215] "stanreg" "summary.lm" +#> [217] "survfit" "survreg" +#> [219] "svy_vglm" "svy2lme" +#> [221] "svychisq" "svyglm" +#> [223] "svyolr" "t1way" +#> [225] "tobit" "trimcibt" +#> [227] "truncreg" "vgam" +#> [229] "vglm" "wbgee" +#> [231] "wblm" "wbm" +#> [233] "wmcpAKP" "yuen" +#> [235] "yuend" "zcpglm" +#> [237] "zeroinfl" "zerotrunc" ``` - **Didn’t find a model?** [File an diff --git a/tests/testthat/test-panelr-asym.R b/tests/testthat/test-panelr-asym.R new file mode 100644 index 000000000..776b90949 --- /dev/null +++ b/tests/testthat/test-panelr-asym.R @@ -0,0 +1,129 @@ +skip_if_not_installed("panelr") +skip_if_not_installed("clubSandwich") +skip_if_not_installed("car") + +data("teen_poverty", package = "panelr") +teen <- panelr::long_panel(teen_poverty, begin = 1, end = 5) +m1 <- panelr::asym(hours ~ lag(pov) + spouse, data = teen, use.wave = TRUE) + +test_that("model_info", { + expect_true(model_info(m1)$is_linear) +}) + +test_that("id_mixed", { + expect_false(is_mixed_model(m1)) +}) + +test_that("find_predictors", { + expect_identical( + find_predictors(m1), + list(conditional = c("pov", "spouse", "wave")) + ) + expect_identical( + find_predictors(m1, flatten = TRUE), + c("pov", "spouse", "wave") + ) + expect_null(find_predictors(m1, effects = "random")) +}) + +test_that("find_random", { + expect_null(find_random(m1)) +}) + +test_that("find_response", { + expect_identical(find_response(m1), "hours") +}) + +test_that("link_inverse", { + expect_equal(link_inverse(m1)(0.2), 0.2, tolerance = 1e-5) +}) + +test_that("find_formula", { + expect_length(find_formula(m1), 1) + expect_equal( + find_formula(m1), + list(conditional = as.formula("hours ~ lag(pov) + spouse + wave")), + ignore_attr = TRUE + ) +}) + +test_that("find_variables", { + expect_identical( + find_variables(m1), + list( + response = "hours", + conditional = c("pov", "spouse", "wave") + ) + ) + expect_identical( + find_variables(m1, flatten = TRUE), + c("hours", "pov", "spouse", "wave") + ) +}) + +test_that("n_obs", { + expect_identical(n_obs(m1), 3453L) +}) + +test_that("linkfun", { + expect_false(is.null(link_function(m1))) +}) + +test_that("find_parameters", { + expect_identical( + find_parameters(m1), + list( + conditional = c("(Intercept)", "+lag(pov)", "-lag(pov)", "+spouse", "-spouse", "wave") + ) + ) + expect_identical(nrow(get_parameters(m1)), 6L) +}) + + +test_that("get_parameters", { + expect_equal( + get_parameters(m1), + data.frame( + Parameter = c( + "(Intercept)", "+lag(pov)", "-lag(pov)", + "+spouse", "-spouse", "wave" + ), + Estimate = c( + 5.07629091766534, -0.695146196282601, 2.74491742707041, + -2.99740859292258, -0.399625620609947, -0.812955475294268 + ), + stringsAsFactors = FALSE + ), + tolerance = 1e-4, + ignore_attr = TRUE + ) +}) + + +test_that("find_terms", { + expect_identical( + find_terms(m1), + list( + response = "hours", + conditional = c("lag(pov)", "spouse", "wave") + ) + ) +}) + +test_that("is_multivariate", { + expect_false(is_multivariate(m1)) +}) + +test_that("find_statistic", { + expect_identical(find_statistic(m1), "t-statistic") +}) + +test_that("get_vcov", { + skip_on_cran() + v <- get_varcov(m1) + expect_identical(dim(v), c(6L, 6L)) + expect_identical( + colnames(v), + c("(Intercept)", "+lag(pov)", "-lag(pov)", "+spouse", "-spouse", "wave") + ) +})