Skip to content

Commit 48c72c6

Browse files
author
Sarah Teichman
authored
Merge pull request #160 from gthopkins/main
Perform test of identical sample sizes in anova.uRegress() to address issue #158
2 parents 12147a0 + 4416be6 commit 48c72c6

9 files changed

Lines changed: 32 additions & 8 deletions

File tree

.github/workflows/R-CMD-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3434

3535
steps:
36-
- uses: actions/checkout@v2
36+
- uses: actions/checkout@v3
3737

3838
- uses: r-lib/actions/setup-r@v2
3939
with:
@@ -50,7 +50,7 @@ jobs:
5050

5151
- name: Restore R package cache
5252
if: runner.os != 'Windows'
53-
uses: actions/cache@v2
53+
uses: actions/cache@v3
5454
with:
5555
path: ${{ env.R_LIBS_USER }}
5656
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Suggests:
2929
tidyverse,
3030
car
3131
VignetteBuilder: knitr
32-
RoxygenNote: 7.2.1
32+
RoxygenNote: 7.3.1
3333
Encoding: UTF-8
3434
Config/testthat/edition: 3
3535
LazyData: true

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ S3method(anova,uRegress)
44
S3method(cooks.distance,uRegress)
55
S3method(dfbeta,uRegress)
66
S3method(dfbetas,uRegress)
7+
S3method(fitted,uRegress)
78
S3method(hatvalues,uRegress)
89
S3method(predict,uRegress)
910
S3method(print,anova.uRegress)
11+
S3method(print,augCoefficients)
1012
S3method(print,lincom)
1113
S3method(print,lincom.joint)
1214
S3method(print,proptest)

R/anova.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ anova.uRegress <- function(object, full_object, test="LRT", robustSE = TRUE, use
5555
}
5656
}
5757

58-
#
5958
if (object$fnctl != full_object$fnctl) {
6059
stop("uRegress objects must be created with the same fnctl!")
6160
}
6261

62+
if (NROW(object$fit$model) != NROW(full_object$fit$model)) {
63+
stop(paste0("The full and reduced models are fit on data with different ",
64+
"sample sizes, but the test is only valid when performed on the ",
65+
"same dataset. This error often occurs when there is missing ",
66+
"data in a variable that is included in the full model but not in the reduced model."))
67+
}
68+
6369
# simple check for nested models
6470
if (object$fnctl != "hazard" & full_object$fnctl!= "hazard") {
6571
if (full_object$fit$rank<=object$fit$rank) {

R/regress_utils.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ printerGlm <- function (x, digits = max(3L, getOption("digits") - 3L), symbolic.
17871787
invisible(x)
17881788
}
17891789

1790+
#' @export
17901791
print.augCoefficients <-
17911792
function (x,...,sigfigs=max(3,getOption("digits")-3),width=9,nonsci.limit=5,Psci=FALSE) {
17921793

@@ -1850,6 +1851,7 @@ print.augCoefficients <-
18501851
invisible(frmtCoefficients)
18511852
}
18521853

1854+
#' @export
18531855
fitted.uRegress <-
18541856
function (object,...,X) {
18551857

R/rigr-package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#'
2424
#' @name rigr-package
2525
#' @aliases rigr-package rigr
26-
#' @docType package
2726
#' @author Scott S. Emerson, Andrew J. Spieker, Brian D.
2827
#' Williamson, Amy D. Willis, Charles Wolock, and Taylor Okonek
2928
#'

man/rigr-package.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_anova.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ reg_full <- regress("mean", y ~ x + z, data = dat, robustSE = FALSE)
77
lm_null <- stats::lm(y ~ x, data = dat)
88
lm_full <- stats::lm(y ~ x + z, data = dat)
99

10+
dat_miss <- dat
11+
dat_miss$x[sample(1:100, 10)] <- NA
12+
reg_full_miss <- regress("mean", y ~ x + z, data = dat_miss)
13+
reg_null_miss <- regress("mean", y ~ z, data = dat_miss)
14+
15+
test_that("anova.uRegress() throws an error if models are fit on different sample sizes", {
16+
expect_error(anova(reg_null_miss, reg_full_miss),
17+
paste0("The full and reduced models are fit on data with different ",
18+
"sample sizes, but the test is only valid when performed on the ",
19+
"same dataset. This error often occurs when there is missing ",
20+
"data in a variable that is included in the full model but not in the reduced model."))
21+
})
22+
23+
test_that("anova.uRegress() does not throw an error if models are fit on same sample size", {
24+
expect_no_error(anova(reg_null, reg_full, robustSE = FALSE))
25+
})
26+
1027

1128
test_that("anova.uRegress() throws an error if at least one of the two input
1229
objects is not of class uRegress", {
@@ -36,7 +53,6 @@ hazard_reg_null <- regress("hazard", Surv(obstime, death)~age, data=mri)
3653
hazard_reg_full <- regress("hazard", Surv(obstime, death)~age+height+weight, data=mri)
3754
rate_reg_full <- regress("rate", obstime ~ age+height+weight, data = mri, robustSE = FALSE)
3855

39-
4056
test_that("anova.uRegress() throws an error if the two input objects are
4157
regressions with different fnctls", {
4258
expect_error(anova(hazard_reg_null, reg_full, robustSE = FALSE),

tests/testthat/test_regress.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ test_that("regress() returns same output as coxph() for fnctl = hazard", {
367367

368368
})
369369

370-
mri2 <- read.table("http://www.emersonstatistics.com/datasets/mri.txt", header = T)
370+
mri2 <- read.table("https://rct-design.com/TeachingMaterials/Datasets/mri.txt", header = T)
371371
mri2$obstime_yrs <- mri2$obstime/365.25
372372
mri2$ldlcat <- cut(mri2$ldl, breaks=c(0, 70, 100, 130, 160, 190, 250), right=FALSE)
373373
mri2$surv <- Surv(mri2$obstime_yrs, mri2$death)

0 commit comments

Comments
 (0)