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]