0
$\begingroup$

I have fit a glmm using the glmer function from the lme4 package. I have found the DHARMa package very helpful for evaluating the fit of my model but am stuck as to what to do to evaluate temporal autocorrelation. I collected data at 14 sites. A data point was collected every 5 hours at each site, so I have multiple observations for each site. Because of this, I do not have a unique time value for each observation in my data-I have 14 observations (one for each site) per time value. The testTemporalAutocorrelation function in the DHARMa package does not like this—when I plug my time variable into the function

testTemporalAutocorrelation(simulationOutput = simulationOutput, 
                            time = data$ObservationNumber)

I get the following error:

Error in testTemporalAutocorrelation(simulationOutput =
simulationOutput,  : testing for temporal autocorrelation requires
unique time values - if you have several observations per location,
use the recalculateResiduals function to aggregate residuals per
location

I have used the recalculateResiduals function, plugging in site as the grouping factor

 simulationOutput1 <- recalculateResiduals(simulationOutput, group=data$site)

However, I am not sure what the next step is. I initially tried:

testTemporalAutocorrelation(simulationOutput1) 

but when I run that, I get the following error:

Error in X[order(z), ] : subscript out of bounds

I am not sure what the next steps are with regards to evaluating temporal autocorrelation. Any thoughts/advice are greatly appreciated, and please let me know if there is any additional information I can provide to clarify my question. Thank you!

$\endgroup$
1
$\begingroup$

I am the developer of DHARMa.

From your question, I realised that there was a typo in the error message - if you have several observations per time step, you have to group the residuals per TIME (so that you have only one residual per time step), not per LOCATION.

I have corrected this, and added a few further examples in the help. This will be rolled out with the next CRAN release, but if you want, you can already install the current development release of DHARM via https://github.com/florianhartig/DHARMa. If you don't want to install the new package version - the updated examples are here

As a side note: for DHARMa specific questions, you will get a faster response if you post your question at https://github.com/florianhartig/DHARMa/issues

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.