I have data samples arranged in a 1000 x 56 array, and I would like to extract the parameters of a Rician distribution that best fits the data in each column. I am using the VGAM package, which seems like a perfect fit, and given the example in the documentation for riceff
vee = exp(2); sigma = exp(1);
y = rrice(n <- 1000, vee, sigma)
fit = vglm(y ~ 1, riceff, trace=TRUE, crit="c")
I figured the following code would work without a problem
nu <- rep(-1,ncol(data))
sigma <- rep(-1,ncol(data))
for( coln in seq(ncol(data)) ) {
fdata <- c(data[,coln])
fit <- vglm( fdata ~ 1, riceff, trace=TRUE, crit="c" )
sigma[coln] <- matrix(Coef(fit)[1])[1,1]
nu[coln] <- matrix(Coef(fit)[2])[1,1]
}
but instead I get the error
VGLM linear loop 1 : coefficients = -723936.834084, 598.301767
Error in if ((temp <- sum(wz[, 1:M, drop = FALSE] < wzepsilon))) warning(paste(temp, :
argument is not interpretable as logical
as for my data, I ran some basic checks
> is.matrix(data)
[1] TRUE
> dim(data)
[1] 1000 56
> summary(data)
V1
Min. :1.402e-05
1st Qu.:9.533e-04
Median :1.548e-03
Mean :1.640e-03
3rd Qu.:2.175e-03
Max. :4.657e-03
... (omitted for brevity)
V56
Min. :5.252e-05
1st Qu.:1.125e-03
Median :1.692e-03
Mean :1.776e-03
3rd Qu.:2.293e-03
Max. :5.903e-03
None of the information in the summary indicates that there is a NaN hidden somewhere, so I am at a loss as to why vglm is failing.
Does anyone have an idea as to what may be the problem? Any insight is greatly appreciated.
As suggested by Ben Bolker, here is the “solution” to my own problem (for future reference):
The
vglmfunction in theVGAMpackage does not necessarily behave well for all data inputs. Since a lot of data is often close to being Rayleigh distributed, the command just exits with that bizarre error (Koay inversion also fails, for similar reasons I assume). If I fit my data against a generalized Rayleigh distribution viagenrayleigh, everything works well enough.One way to try both, as Ben suggested, is to use
tryortryCatchto attempt both, or to emitNAvalues when the fitting function breaks down.