Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions inst/Regression/coxphfit.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@
endif

## --- X and T -----------------------------------------------------------
if (! (isnumeric (X) && isreal (X) && ismatrix (X) && ! isempty (X)))
if (! (isnumeric (X) && isreal (X) && ismatrix (X)))
error ("coxphfit: X must be a real numeric matrix.");
endif
if (! (isnumeric (T) && isreal (T) && ! isempty (T)))
if (! (isnumeric (T) && isreal (T)))
error ("coxphfit: T must be a real numeric vector.");
endif
## T is either a vector of event times or, in the counting process form, an
Expand All @@ -177,7 +177,7 @@
error (strcat ("coxphfit: each row of T must give a (start, stop]", ...
" interval with start strictly less than stop."));
endif
elseif (isvector (T))
elseif (isvector (T) || isempty (T))
T = T(:);
Tstart = -Inf (numel (T), 1);
else
Expand All @@ -188,6 +188,11 @@
if (rows (X) != n)
error ("coxphfit: T must have one element for each row of X.");
endif

if (n == 0)
error ("coxphfit: X and T must contain at least one observation.");
endif

p = columns (X);

## --- name/value pairs --------------------------------------------------
Expand Down Expand Up @@ -947,3 +952,9 @@
## A constant column is reported, not silently absorbed
%!warning<coxphfit: the Cox model cannot have a constant term in X.> ...
%! coxphfit ([X, ones(10,1)], T);

## Edge cases with empty arrays
%!error <coxphfit: X and T must contain at least one observation.> ...
%! coxphfit ([], [])
%!error <coxphfit: X and T must contain at least one observation.> ...
%! coxphfit (zeros (0, 3), zeros (0, 1))