Skip to content

Commit 9b51a86

Browse files
committed
R() without object failed for some forms of interval censoring
git-svn-id: svn://svn.r-forge.r-project.org/svnroot/ctm@2611 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
1 parent 89a6e2f commit 9b51a86

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

pkg/mlt/R/R.R

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ R.numeric <- function(object = NA, cleft = NA, cright = NA,
219219

220220
### treat extremely small intervals as `exact' observations
221221
d <- cright - cleft
222+
if (length(object) == 1L && all(is.na(object)))
223+
object <- rep(NA, length(d))
222224
if (any(!is.na(d) | is.finite(d))) {
223225
if (any(d < 0, na.rm = TRUE)) stop("cleft > cright")
224226
i <- (d < tol)

pkg/mlt/tests/bugfixes.R

+6
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ m <- mlt(ctm(response = Bernstein_basis(numeric_var("y", bounds = c(0, 1)), orde
134134
mi <- mlt(ctm(response = Bernstein_basis(numeric_var("y", bounds = c(0, 1)), order = 1)),
135135
data = d[-ic,,drop = FALSE], theta = c(-1, 1))
136136
all.equal(logLik(m), logLik(mi))
137+
138+
### R with interval censoring
139+
lwr <- as.double(1:3)
140+
upr <- as.double(2:4)
141+
upr[2] <- 2
142+
R(cleft = lwr, cright = upr)

pkg/mlt/tests/bugfixes.Rout.save

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
3-
Copyright (C) 2024 The R Foundation for Statistical Computing
2+
R version 4.4.3 (2025-02-28) -- "Trophy Case"
3+
Copyright (C) 2025 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -170,6 +170,13 @@ Coefficients: 30.951 38.885 42.523 -0.01508 -0.058906 -0.12136 -0.054061 -0.4769
170170
> all.equal(logLik(m), logLik(mi))
171171
[1] TRUE
172172
>
173+
> ### R with interval censoring
174+
> lwr <- as.double(1:3)
175+
> upr <- as.double(2:4)
176+
> upr[2] <- 2
177+
> R(cleft = lwr, cright = upr)
178+
[1] ( 1, 2] 2 ( 3, 4]
179+
>
173180
> proc.time()
174181
user system elapsed
175-
0.933 0.068 0.997
182+
0.816 0.068 0.879

0 commit comments

Comments
 (0)