Bug 14690 - Error in 'loglin' when 'margin' is a single factor and 'param' is TRUE
Error in 'loglin' when 'margin' is a single factor and 'param' is TRUE
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Analyses
R 2.13.1 patched
PowerPC Mac OS X v10.5
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-29 20:57 UTC by John Bryant
Modified: 2011-10-03 12:33 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Bryant 2011-09-29 20:57:23 UTC
Function 'loglin' throws an error when argument 'margin' consists of a single element of length one. An example:

> loglin(HairEyeColor, margin = list(1), param = TRUE)

produces error message

"Error in dyadic[i - 1, ] : incorrect number of dimensions"


The error is caused by the line 

dyadic <- dyadic[order(rowSums(dyadic)), ]

This line coerces 'dyadic' from a matrix to a vector if the original 'margin' argument consists of a single element of length 1, since in this case 'dyadic' will only have one column. If 'dyadic' is coerced to a vector, then the later statement

vars <- which(dyadic[i - 1, ] > 0)

will fail because it assumes that 'dyadic' is a matrix.


Adding a 'drop = FALSE' argument to the earlier line solves the problem:

dyadic <- dyadic[order(rowSums(dyadic)), , drop = FALSE]