diff --git a/tests/testthat/_snaps/backward-aic-details.md b/tests/testthat/_snaps/backward-aic-details.md new file mode 100644 index 00000000..3f132954 --- /dev/null +++ b/tests/testthat/_snaps/backward-aic-details.md @@ -0,0 +1,123 @@ +# output is as expected when details == TRUE + + Code + blr_step_aic_backward(model, details = TRUE) + Output + Backward Elimination Method + --------------------------- + + Candidate Terms: + + 1 . female + 2 . read + 3 . science + 4 . math + 5 . prog + 6 . socst + + Step 0: AIC = 162.4241 + honcomp ~ female + read + science + math + prog + socst + + ------------------------------------------------- + Variable DF AIC BIC Deviance + ------------------------------------------------- + prog 1 158.953 178.743 146.953 + socst 1 160.745 183.834 146.745 + read 1 163.394 186.482 149.394 + science 1 163.815 186.903 149.815 + female 1 169.570 192.658 155.570 + math 1 170.017 193.105 156.017 + ------------------------------------------------- + + + x prog + + + Step 1 : AIC = 158.9527 + honcomp ~ female + read + science + math + socst + + ------------------------------------------------- + Variable DF AIC BIC Deviance + ------------------------------------------------- + socst 1 157.286 173.777 147.286 + science 1 159.941 176.432 149.941 + read 1 160.307 176.798 150.307 + female 1 166.114 182.606 156.114 + math 1 168.669 185.161 158.669 + ------------------------------------------------- + + x socst + + + Step 2 : AIC = 157.2856 + honcomp ~ female + read + science + math + + ------------------------------------------------- + Variable DF AIC BIC Deviance + ------------------------------------------------- + science 1 158.420 171.613 150.420 + read 1 160.658 173.851 152.658 + female 1 164.988 178.181 156.988 + math 1 168.236 181.430 160.236 + ------------------------------------------------- + + No more variables to be removed. + + Variables Removed: + + - prog + - socst + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 195 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 + female1 1 1.3622 0.4605 2.9580 0.0031 + read 1 0.0631 0.0281 2.2455 0.0247 + science 1 0.0569 0.0326 1.7429 0.0814 + math 1 0.1113 0.0338 3.2992 0.0010 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8835 Somers' D 0.7669 + % Discordant 0.1165 Gamma 0.7669 + % Tied 0.0000 Tau-a 0.3003 + Pairs 7791 c 0.8835 + --------------------------------------------------------------- + + + + Backward Elimination Summary + -------------------------------------------- + Variable AIC BIC Deviance + -------------------------------------------- + Full Model 162.424 188.811 146.424 + prog 158.953 178.743 146.953 + socst 157.286 173.777 147.286 + -------------------------------------------- + + diff --git a/tests/testthat/_snaps/backward-aic.md b/tests/testthat/_snaps/backward-aic.md new file mode 100644 index 00000000..8b3e8ab9 --- /dev/null +++ b/tests/testthat/_snaps/backward-aic.md @@ -0,0 +1,17 @@ +# output from backward variable elimination is as expected + + Code + blr_step_aic_backward(model) + Output + + + Backward Elimination Summary + -------------------------------------------- + Variable AIC BIC Deviance + -------------------------------------------- + Full Model 162.424 188.811 146.424 + prog 158.953 178.743 146.953 + socst 157.286 173.777 147.286 + -------------------------------------------- + + diff --git a/tests/testthat/_snaps/backward-elimination.md b/tests/testthat/_snaps/backward-elimination.md deleted file mode 100644 index 42ed5634..00000000 --- a/tests/testthat/_snaps/backward-elimination.md +++ /dev/null @@ -1,389 +0,0 @@ -# print output from backward variable elimination is as expected - - Code - blr_step_aic_backward(model) - Output - - - Backward Elimination Summary - -------------------------------------------- - Variable AIC BIC Deviance - -------------------------------------------- - Full Model 162.424 188.811 146.424 - prog 158.953 178.743 146.953 - socst 157.286 173.777 147.286 - -------------------------------------------- - - -# print output from backward variable p elimination is as expected - - Code - blr_step_p_backward(model) - Output - Backward Elimination Method - --------------------------- - - Candidate Terms: - - 1 . female - 2 . read - 3 . science - 4 . math - 5 . prog - 6 . socst - - We are eliminating variables based on p value... - - Variables Removed: - - - prog - - socst - - No more variables satisfy the condition of p value = 0.3 - - - Final Model Output - ------------------ - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 195 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8835 Somers' D 0.7669 - % Discordant 0.1165 Gamma 0.7669 - % Tied 0.0000 Tau-a 0.3003 - Pairs 7791 c 0.8835 - --------------------------------------------------------------- - - - - Elimination Summary - ---------------------------------------------------- - Variable - Step Removed AIC BIC Deviance - ---------------------------------------------------- - 1 prog 158.9527 178.7427 146.9527 - 2 socst 157.2856 173.7772 147.2856 - ---------------------------------------------------- - -# output from backward variable elimination is as expected when details == TRUE - - Code - blr_step_aic_backward(model, details = TRUE) - Output - Backward Elimination Method - --------------------------- - - Candidate Terms: - - 1 . female - 2 . read - 3 . science - 4 . math - 5 . prog - 6 . socst - - Step 0: AIC = 162.4241 - honcomp ~ female + read + science + math + prog + socst - - ------------------------------------------------- - Variable DF AIC BIC Deviance - ------------------------------------------------- - prog 1 158.953 178.743 146.953 - socst 1 160.745 183.834 146.745 - read 1 163.394 186.482 149.394 - science 1 163.815 186.903 149.815 - female 1 169.570 192.658 155.570 - math 1 170.017 193.105 156.017 - ------------------------------------------------- - - - x prog - - - Step 1 : AIC = 158.9527 - honcomp ~ female + read + science + math + socst - - ------------------------------------------------- - Variable DF AIC BIC Deviance - ------------------------------------------------- - socst 1 157.286 173.777 147.286 - science 1 159.941 176.432 149.941 - read 1 160.307 176.798 150.307 - female 1 166.114 182.606 156.114 - math 1 168.669 185.161 158.669 - ------------------------------------------------- - - x socst - - - Step 2 : AIC = 157.2856 - honcomp ~ female + read + science + math - - ------------------------------------------------- - Variable DF AIC BIC Deviance - ------------------------------------------------- - science 1 158.420 171.613 150.420 - read 1 160.658 173.851 152.658 - female 1 164.988 178.181 156.988 - math 1 168.236 181.430 160.236 - ------------------------------------------------- - - No more variables to be removed. - - Variables Removed: - - - prog - - socst - - - Final Model Output - ------------------ - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 195 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8835 Somers' D 0.7669 - % Discordant 0.1165 Gamma 0.7669 - % Tied 0.0000 Tau-a 0.3003 - Pairs 7791 c 0.8835 - --------------------------------------------------------------- - - - - Backward Elimination Summary - -------------------------------------------- - Variable AIC BIC Deviance - -------------------------------------------- - Full Model 162.424 188.811 146.424 - prog 158.953 178.743 146.953 - socst 157.286 173.777 147.286 - -------------------------------------------- - - -# output from backward variable elimination p is as expected when details == TRUE - - Code - blr_step_p_backward(model, details = TRUE) - Output - Backward Elimination Method - --------------------------- - - Candidate Terms: - - 1 . female - 2 . read - 3 . science - 4 . math - 5 . prog - 6 . socst - - We are eliminating variables based on p value... - - - prog - - Backward Elimination: Step 1 - - Variable prog Removed - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 194 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -14.8131 2.2101 -6.7024 0.0000 - female1 1 1.3351 0.4634 2.8813 0.0040 - read 1 0.0558 0.0309 1.8050 0.0711 - science 1 0.0561 0.0329 1.7036 0.0885 - math 1 0.1086 0.0342 3.1761 0.0015 - socst 1 0.0155 0.0270 0.5738 0.5661 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8822 Somers' D 0.7643 - % Discordant 0.1178 Gamma 0.7643 - % Tied 0.0000 Tau-a 0.2992 - Pairs 7791 c 0.8822 - --------------------------------------------------------------- - - - - - socst - - Backward Elimination: Step 2 - - Variable socst Removed - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 195 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8835 Somers' D 0.7669 - % Discordant 0.1165 Gamma 0.7669 - % Tied 0.0000 Tau-a 0.3003 - Pairs 7791 c 0.8835 - --------------------------------------------------------------- - - - - - No more variables satisfy the condition of p value = 0.3 - - - Variables Removed: - - - prog - - socst - - - Final Model Output - ------------------ - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 195 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8835 Somers' D 0.7669 - % Discordant 0.1165 Gamma 0.7669 - % Tied 0.0000 Tau-a 0.3003 - Pairs 7791 c 0.8835 - --------------------------------------------------------------- - - - - Elimination Summary - ---------------------------------------------------- - Variable - Step Removed AIC BIC Deviance - ---------------------------------------------------- - 1 prog 158.9527 178.7427 146.9527 - 2 socst 157.2856 173.7772 147.2856 - ---------------------------------------------------- - diff --git a/tests/testthat/_snaps/backward-p-details.md b/tests/testthat/_snaps/backward-p-details.md new file mode 100644 index 00000000..0d539ec3 --- /dev/null +++ b/tests/testthat/_snaps/backward-p-details.md @@ -0,0 +1,171 @@ +# output is as expected when details == TRUE + + Code + blr_step_p_backward(model, details = TRUE) + Output + Backward Elimination Method + --------------------------- + + Candidate Terms: + + 1 . female + 2 . read + 3 . science + 4 . math + 5 . prog + 6 . socst + + We are eliminating variables based on p value... + + - prog + + Backward Elimination: Step 1 + + Variable prog Removed + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 194 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -14.8131 2.2101 -6.7024 0.0000 + female1 1 1.3351 0.4634 2.8813 0.0040 + read 1 0.0558 0.0309 1.8050 0.0711 + science 1 0.0561 0.0329 1.7036 0.0885 + math 1 0.1086 0.0342 3.1761 0.0015 + socst 1 0.0155 0.0270 0.5738 0.5661 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8822 Somers' D 0.7643 + % Discordant 0.1178 Gamma 0.7643 + % Tied 0.0000 Tau-a 0.2992 + Pairs 7791 c 0.8822 + --------------------------------------------------------------- + + + + - socst + + Backward Elimination: Step 2 + + Variable socst Removed + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 195 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 + female1 1 1.3622 0.4605 2.9580 0.0031 + read 1 0.0631 0.0281 2.2455 0.0247 + science 1 0.0569 0.0326 1.7429 0.0814 + math 1 0.1113 0.0338 3.2992 0.0010 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8835 Somers' D 0.7669 + % Discordant 0.1165 Gamma 0.7669 + % Tied 0.0000 Tau-a 0.3003 + Pairs 7791 c 0.8835 + --------------------------------------------------------------- + + + + + No more variables satisfy the condition of p value = 0.3 + + + Variables Removed: + + - prog + - socst + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 195 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 + female1 1 1.3622 0.4605 2.9580 0.0031 + read 1 0.0631 0.0281 2.2455 0.0247 + science 1 0.0569 0.0326 1.7429 0.0814 + math 1 0.1113 0.0338 3.2992 0.0010 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8835 Somers' D 0.7669 + % Discordant 0.1165 Gamma 0.7669 + % Tied 0.0000 Tau-a 0.3003 + Pairs 7791 c 0.8835 + --------------------------------------------------------------- + + + + Elimination Summary + ---------------------------------------------------- + Variable + Step Removed AIC BIC Deviance + ---------------------------------------------------- + 1 prog 158.9527 178.7427 146.9527 + 2 socst 157.2856 173.7772 147.2856 + ---------------------------------------------------- + diff --git a/tests/testthat/_snaps/backward-p.md b/tests/testthat/_snaps/backward-p.md new file mode 100644 index 00000000..0f07f0fc --- /dev/null +++ b/tests/testthat/_snaps/backward-p.md @@ -0,0 +1,78 @@ +# output from backward variable p elimination is as expected + + Code + blr_step_p_backward(model) + Output + Backward Elimination Method + --------------------------- + + Candidate Terms: + + 1 . female + 2 . read + 3 . science + 4 . math + 5 . prog + 6 . socst + + We are eliminating variables based on p value... + + Variables Removed: + + - prog + - socst + + No more variables satisfy the condition of p value = 0.3 + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 195 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 + female1 1 1.3622 0.4605 2.9580 0.0031 + read 1 0.0631 0.0281 2.2455 0.0247 + science 1 0.0569 0.0326 1.7429 0.0814 + math 1 0.1113 0.0338 3.2992 0.0010 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8835 Somers' D 0.7669 + % Discordant 0.1165 Gamma 0.7669 + % Tied 0.0000 Tau-a 0.3003 + Pairs 7791 c 0.8835 + --------------------------------------------------------------- + + + + Elimination Summary + ---------------------------------------------------- + Variable + Step Removed AIC BIC Deviance + ---------------------------------------------------- + 1 prog 158.9527 178.7427 146.9527 + 2 socst 157.2856 173.7772 147.2856 + ---------------------------------------------------- + diff --git a/tests/testthat/_snaps/forward-selection.md b/tests/testthat/_snaps/forward-aic-details.md similarity index 53% rename from tests/testthat/_snaps/forward-selection.md rename to tests/testthat/_snaps/forward-aic-details.md index ccf8f490..7fc96a8e 100644 --- a/tests/testthat/_snaps/forward-selection.md +++ b/tests/testthat/_snaps/forward-aic-details.md @@ -1,20 +1,5 @@ # output from forward variable selection is as expected - Code - blr_step_aic_forward(model) - Output - - Selection Summary - --------------------------------------------------- - Step Variable AIC BIC Deviance - --------------------------------------------------- - 1 read 183.063 189.660 179.063 - 2 female 176.887 176.887 176.887 - 3 science 168.236 168.236 168.236 - --------------------------------------------------- - ---- - Code blr_step_aic_forward(model, details = TRUE) Output @@ -123,76 +108,3 @@ 3 science 168.236 168.236 168.236 --------------------------------------------------- -# output from forward variable p selection is as expected - - Code - blr_step_p_forward(model) - Output - Forward Selection Method - --------------------------- - - Candidate Terms: - - 1. female - 2. read - 3. science - - We are selecting variables based on p value... - - Variables Entered: - - - read - - female - - science - - - Final Model Output - ------------------ - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------ - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------ - data honcomp 200 199 196 TRUE - ------------------------------------------------------------------------ - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 147 1 53 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ----------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) - ----------------------------------------------------------------- - (Intercept) 1 -12.7772 1.9755 -6.4677 0.0000 - read 1 0.1035 0.0258 4.0186 1e-04 - female1 1 1.4825 0.4474 3.3139 9e-04 - science 1 0.0948 0.0305 3.1129 0.0019 - ----------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8561 Somers' D 0.7147 - % Discordant 0.1425 Gamma 0.7136 - % Tied 0.0014 Tau-a 0.2794 - Pairs 7791 c 0.8568 - --------------------------------------------------------------- - - - Selection Summary - ---------------------------------------------------- - Variable - Step Entered AIC BIC Deviance - ---------------------------------------------------- - 1 read 183.0630 189.6596 179.0630 - 2 female 176.8874 186.7824 170.8874 - 3 science 168.2364 181.4296 160.2364 - ---------------------------------------------------- - diff --git a/tests/testthat/_snaps/forward-aic.md b/tests/testthat/_snaps/forward-aic.md new file mode 100644 index 00000000..2ac7a10e --- /dev/null +++ b/tests/testthat/_snaps/forward-aic.md @@ -0,0 +1,15 @@ +# output from forward variable selection is as expected + + Code + blr_step_aic_forward(model) + Output + + Selection Summary + --------------------------------------------------- + Step Variable AIC BIC Deviance + --------------------------------------------------- + 1 read 183.063 189.660 179.063 + 2 female 176.887 176.887 176.887 + 3 science 168.236 168.236 168.236 + --------------------------------------------------- + diff --git a/tests/testthat/_snaps/forward-p.md b/tests/testthat/_snaps/forward-p.md new file mode 100644 index 00000000..7ac5502c --- /dev/null +++ b/tests/testthat/_snaps/forward-p.md @@ -0,0 +1,73 @@ +# output from forward variable p selection is as expected + + Code + blr_step_p_forward(model) + Output + Forward Selection Method + --------------------------- + + Candidate Terms: + + 1. female + 2. read + 3. science + + We are selecting variables based on p value... + + Variables Entered: + + - read + - female + - science + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 196 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -12.7772 1.9755 -6.4677 0.0000 + read 1 0.1035 0.0258 4.0186 1e-04 + female1 1 1.4825 0.4474 3.3139 9e-04 + science 1 0.0948 0.0305 3.1129 0.0019 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8561 Somers' D 0.7147 + % Discordant 0.1425 Gamma 0.7136 + % Tied 0.0014 Tau-a 0.2794 + Pairs 7791 c 0.8568 + --------------------------------------------------------------- + + + Selection Summary + ---------------------------------------------------- + Variable + Step Entered AIC BIC Deviance + ---------------------------------------------------- + 1 read 183.0630 189.6596 179.0630 + 2 female 176.8874 186.7824 170.8874 + 3 science 168.2364 181.4296 160.2364 + ---------------------------------------------------- + diff --git a/tests/testthat/_snaps/stepwise-aic.md b/tests/testthat/_snaps/stepwise-aic.md new file mode 100644 index 00000000..47a00b75 --- /dev/null +++ b/tests/testthat/_snaps/stepwise-aic.md @@ -0,0 +1,43 @@ +# output from forward variable selection is as expected + + Code + blr_step_aic_both(model) + Output + Stepwise Selection Method + ------------------------- + + Candidate Terms: + + 1 . x1 + 2 . x2 + 3 . x3 + 4 . x4 + 5 . x5 + 6 . x6 + + + Variables Entered/Removed: + + - x6 added + - x1 added + - x3 added + - x2 added + - x6 removed + - x5 added + + No more variables to be added or removed. + + + Stepwise Summary + ----------------------------------------------------------- + Variable Method AIC BIC Deviance + ----------------------------------------------------------- + x6 addition 18869.627 18885.434 18865.627 + x1 addition 18571.376 18595.087 18565.376 + x3 addition 18016.724 18048.338 18008.724 + x2 addition 16642.374 16681.891 16632.374 + x6 removal 16640.653 16672.267 16632.653 + x5 addition 16639.219 16678.736 16629.219 + ----------------------------------------------------------- + + diff --git a/tests/testthat/_snaps/stepwise-selection.md b/tests/testthat/_snaps/stepwise-p-details.md similarity index 68% rename from tests/testthat/_snaps/stepwise-selection.md rename to tests/testthat/_snaps/stepwise-p-details.md index 94142d3b..39122f66 100644 --- a/tests/testthat/_snaps/stepwise-selection.md +++ b/tests/testthat/_snaps/stepwise-p-details.md @@ -1,126 +1,4 @@ -# print output from forward variable selection is as expected - - Code - blr_step_aic_both(model) - Output - Stepwise Selection Method - ------------------------- - - Candidate Terms: - - 1 . x1 - 2 . x2 - 3 . x3 - 4 . x4 - 5 . x5 - 6 . x6 - - - Variables Entered/Removed: - - - x6 added - - x1 added - - x3 added - - x2 added - - x6 removed - - x5 added - - No more variables to be added or removed. - - - Stepwise Summary - ----------------------------------------------------------- - Variable Method AIC BIC Deviance - ----------------------------------------------------------- - x6 addition 18869.627 18885.434 18865.627 - x1 addition 18571.376 18595.087 18565.376 - x3 addition 18016.724 18048.338 18008.724 - x2 addition 16642.374 16681.891 16632.374 - x6 removal 16640.653 16672.267 16632.653 - x5 addition 16639.219 16678.736 16629.219 - ----------------------------------------------------------- - - ---- - - Code - blr_step_p_both(model) - Output - Stepwise Selection Method - --------------------------- - - Candidate Terms: - - 1. x1 - 2. x2 - 3. x3 - 4. x4 - 5. x5 - 6. x6 - - We are selecting variables based on p value... - - Variables Entered/Removed: - - - x6 added - - x5 added - - x6 added - - No more variables to be added/removed. - - - Final Model Output - ------------------ - - - Creating model overview. - - Creating response profile. - - Extracting maximum likelihood estimates. - - Estimating concordant and discordant pairs. - Model Overview - ------------------------------------------------------------------------- - Data Set Resp Var Obs. Df. Model Df. Residual Convergence - ------------------------------------------------------------------------- - data y 20000 19999 19995 TRUE - ------------------------------------------------------------------------- - - Response Summary - -------------------------------------------------------- - Outcome Frequency Outcome Frequency - -------------------------------------------------------- - 0 10041 1 9959 - -------------------------------------------------------- - - Maximum Likelihood Estimates - ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) - ------------------------------------------------------------------ - (Intercept) 1 -1.5228 0.0287 -53.1302 0.0000 - x1 1 1.0276 0.0212 48.4927 0.0000 - x2 1 0.9807 0.0209 46.9690 0.0000 - x3 1 1.0260 0.0213 48.2799 0.0000 - x5 1 0.0357 0.0192 1.8531 0.0639 - ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses - --------------------------------------------------------------- - % Concordant 0.8911 Somers' D 0.7821 - % Discordant 0.1089 Gamma 0.7821 - % Tied 0.0000 Tau-a 0.3911 - Pairs 99998319 c 0.8911 - --------------------------------------------------------------- - - - Stepwise Selection Summary - ---------------------------------------------------------------------- - Added/ - Step Variable Removed AIC BIC C(p) - ---------------------------------------------------------------------- - 1 x1 addition 16642.374 16681.891 16632.3740 - 2 x2 addition 16640.883 16688.304 16628.8830 - 3 x3 removal 16639.219 16678.736 16629.2190 - ---------------------------------------------------------------------- - -# print output from forward variable p selection is as expected +# output from forward variable p selection is as expected Code blr_step_p_both(model, details = TRUE) diff --git a/tests/testthat/_snaps/stepwise-p.md b/tests/testthat/_snaps/stepwise-p.md new file mode 100644 index 00000000..ee1716fd --- /dev/null +++ b/tests/testthat/_snaps/stepwise-p.md @@ -0,0 +1,79 @@ +# output from forward variable selection is as expected + + Code + blr_step_p_both(model) + Output + Stepwise Selection Method + --------------------------- + + Candidate Terms: + + 1. x1 + 2. x2 + 3. x3 + 4. x4 + 5. x5 + 6. x6 + + We are selecting variables based on p value... + + Variables Entered/Removed: + + - x6 added + - x5 added + - x6 added + + No more variables to be added/removed. + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------- + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------- + data y 20000 19999 19995 TRUE + ------------------------------------------------------------------------- + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 10041 1 9959 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ------------------------------------------------------------------ + Parameter DF Estimate Std. Error z value Pr(>|z|) + ------------------------------------------------------------------ + (Intercept) 1 -1.5228 0.0287 -53.1302 0.0000 + x1 1 1.0276 0.0212 48.4927 0.0000 + x2 1 0.9807 0.0209 46.9690 0.0000 + x3 1 1.0260 0.0213 48.2799 0.0000 + x5 1 0.0357 0.0192 1.8531 0.0639 + ------------------------------------------------------------------ + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8911 Somers' D 0.7821 + % Discordant 0.1089 Gamma 0.7821 + % Tied 0.0000 Tau-a 0.3911 + Pairs 99998319 c 0.8911 + --------------------------------------------------------------- + + + Stepwise Selection Summary + ---------------------------------------------------------------------- + Added/ + Step Variable Removed AIC BIC C(p) + ---------------------------------------------------------------------- + 1 x1 addition 16642.374 16681.891 16632.3740 + 2 x2 addition 16640.883 16688.304 16628.8830 + 3 x3 removal 16639.219 16678.736 16629.2190 + ---------------------------------------------------------------------- + diff --git a/tests/testthat/test-backward-aic-details.R b/tests/testthat/test-backward-aic-details.R new file mode 100644 index 00000000..a48a6f7c --- /dev/null +++ b/tests/testthat/test-backward-aic-details.R @@ -0,0 +1,10 @@ +test_that("output is as expected when details == TRUE", { + + model <- glm( + honcomp ~ female + read + science + math + prog + socst, + data = hsb2, family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_backward(model, details = TRUE)) + +}) diff --git a/tests/testthat/test-backward-aic.R b/tests/testthat/test-backward-aic.R new file mode 100644 index 00000000..2585357b --- /dev/null +++ b/tests/testthat/test-backward-aic.R @@ -0,0 +1,10 @@ +test_that("output from backward variable elimination is as expected", { + + model <- glm( + honcomp ~ female + read + science + math + prog + socst, + data = hsb2, family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_backward(model)) + +}) diff --git a/tests/testthat/test-backward-elimination.R b/tests/testthat/test-backward-elimination.R index bf5b039a..3b3d9294 100644 --- a/tests/testthat/test-backward-elimination.R +++ b/tests/testthat/test-backward-elimination.R @@ -22,48 +22,3 @@ test_that("output from backward variable p elimination is as expected", { expect_equal(actual, expected) }) -test_that("print output from backward variable elimination is as expected", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_aic_backward(model)) - -}) - -test_that("print output from backward variable p elimination is as expected", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_p_backward(model)) - -}) - -test_that("output from backward variable elimination is as expected when details == TRUE", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_aic_backward(model, details = TRUE)) - -}) - -test_that("output from backward variable elimination p is as expected when details == TRUE", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_p_backward(model, details = TRUE)) - -}) - - diff --git a/tests/testthat/test-backward-p-details.R b/tests/testthat/test-backward-p-details.R new file mode 100644 index 00000000..7e548eed --- /dev/null +++ b/tests/testthat/test-backward-p-details.R @@ -0,0 +1,10 @@ +test_that("output is as expected when details == TRUE", { + + model <- glm( + honcomp ~ female + read + science + math + prog + socst, + data = hsb2, family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_p_backward(model, details = TRUE)) + +}) diff --git a/tests/testthat/test-backward-p.R b/tests/testthat/test-backward-p.R new file mode 100644 index 00000000..acbd1cf1 --- /dev/null +++ b/tests/testthat/test-backward-p.R @@ -0,0 +1,10 @@ +test_that("output from backward variable p elimination is as expected", { + + model <- glm( + honcomp ~ female + read + science + math + prog + socst, + data = hsb2, family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_p_backward(model)) + +}) diff --git a/tests/testthat/test-forward-aic-details.R b/tests/testthat/test-forward-aic-details.R new file mode 100644 index 00000000..db4134f3 --- /dev/null +++ b/tests/testthat/test-forward-aic-details.R @@ -0,0 +1,10 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm( + honcomp ~ female + read + science, data = hsb2, + family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_forward(model, details = TRUE)) + +}) diff --git a/tests/testthat/test-forward-aic.R b/tests/testthat/test-forward-aic.R new file mode 100644 index 00000000..eb51e549 --- /dev/null +++ b/tests/testthat/test-forward-aic.R @@ -0,0 +1,10 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm( + honcomp ~ female + read + science, data = hsb2, + family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_forward(model)) + +}) diff --git a/tests/testthat/test-forward-p.R b/tests/testthat/test-forward-p.R new file mode 100644 index 00000000..c88e1af0 --- /dev/null +++ b/tests/testthat/test-forward-p.R @@ -0,0 +1,11 @@ +test_that("output from forward variable p selection is as expected", { + + model <- glm( + honcomp ~ female + read + science, data = hsb2, + family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_p_forward(model)) + +}) + diff --git a/tests/testthat/test-forward-selection.R b/tests/testthat/test-forward-selection.R index 8cfe1a01..d783ee02 100644 --- a/tests/testthat/test-forward-selection.R +++ b/tests/testthat/test-forward-selection.R @@ -22,38 +22,3 @@ test_that("output from forward variable p selection is as expected", { expect_equal(actual, expected) }) - -test_that("output from forward variable selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_aic_forward(model)) - -}) - -test_that("output from forward variable p selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_p_forward(model)) - -}) - -test_that("output from forward variable selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - expect_snapshot(blr_step_aic_forward(model, details = TRUE)) - -}) - - diff --git a/tests/testthat/test-stepwise-aic.R b/tests/testthat/test-stepwise-aic.R new file mode 100644 index 00000000..2a0c4fe6 --- /dev/null +++ b/tests/testthat/test-stepwise-aic.R @@ -0,0 +1,6 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) + expect_snapshot(blr_step_aic_both(model)) + +}) diff --git a/tests/testthat/test-stepwise-p-details.R b/tests/testthat/test-stepwise-p-details.R new file mode 100644 index 00000000..a2d0cefc --- /dev/null +++ b/tests/testthat/test-stepwise-p-details.R @@ -0,0 +1,6 @@ +test_that("output from forward variable p selection is as expected", { + + model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) + expect_snapshot(blr_step_p_both(model, details = TRUE)) + +}) diff --git a/tests/testthat/test-stepwise-p.R b/tests/testthat/test-stepwise-p.R new file mode 100644 index 00000000..77ac6914 --- /dev/null +++ b/tests/testthat/test-stepwise-p.R @@ -0,0 +1,7 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) + expect_snapshot(blr_step_p_both(model)) + +}) + diff --git a/tests/testthat/test-stepwise-selection.R b/tests/testthat/test-stepwise-selection.R index 40939827..0c3c7d3d 100644 --- a/tests/testthat/test-stepwise-selection.R +++ b/tests/testthat/test-stepwise-selection.R @@ -16,23 +16,3 @@ test_that("output from stepwise variable p selection is as expected", { expect_equal(actual, expected) }) -test_that("print output from forward variable selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - expect_snapshot(blr_step_aic_both(model)) - -}) - -test_that("print output from forward variable selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - expect_snapshot(blr_step_p_both(model)) - -}) - -test_that("print output from forward variable p selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - expect_snapshot(blr_step_p_both(model, details = TRUE)) - -})