Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error for ds models with covariates and adjustments #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erex opened this issue Feb 13, 2023 · 6 comments
Closed

Error for ds models with covariates and adjustments #156

erex opened this issue Feb 13, 2023 · 6 comments
Assignees
Labels

Comments

@erex
Copy link
Member

erex commented Feb 13, 2023

If user attempts to fit a model with covariates and adjustments specified, this message is returned (using amakihi)

mas_adj <- ds(amakihi, transect = "point", key="hn", adjustment = "cos", formula=~MAS, truncation = 82.5) 
Model contains covariate term(s): no adjustment terms will be included. 
Fitting half-normal key function 
Error in covar_fields[i] <- colnames(data)[index] :    replacement has length zero 
AIC= 10826.537

This is the expected behaviour.

However, if the number of adjustment terms is specified, a model with both covariates and adjustment terms it fitted:

> mas <- ds(amakihi, transect = "point", key="hn", adjustment = "cos", formula=~MAS, truncation = 82.5, nadj=1)
Fitting half-normal key function with cosine(2) adjustments
Error in covar_fields[i] <- colnames(data)[index] : 
  replacement has length zero
AIC= 10813.546
> summary(mas)

Summary for distance analysis 
Number of observations :  1243 
Distance range         :  0  -  82.5 

Model : Half-normal key function with cosine adjustment term of order 2 
AIC   : 10813.55 

Detection function parameters
Scale coefficient(s):  
                 estimate           se
(Intercept)  3.6680796035 0.0448874309
MAS         -0.0007460832 0.0002518454

Adjustment term coefficient(s):  
             estimate         se
cos, order 2  0.16759 0.04247431

                        Estimate           SE         CV
Average p              0.2755222   0.01853751 0.06728136
N in covered region 4511.4327728 322.54635589 0.07149533

This is unexpected (and undocumented) behaviour. Plot below shows PDF for MAS=c(60, 120); note deformed shape resulting from inclusing of an adjustment term as well. Do we want users to be able to fit such models or not?

Rplot01

@LHMarshall LHMarshall self-assigned this Mar 1, 2023
@LHMarshall LHMarshall added this to the Distance 1.0.8 milestone Mar 1, 2023
@lenthomas lenthomas added the bug label Apr 4, 2023
@LHMarshall
Copy link
Member

@erex @len what were we going to do with this?

@erex
Copy link
Member Author

erex commented May 25, 2023

I remember a difference of opinion about this at our DistDev meeting. Len labelled it as a bug on 04Apr23, I agree with that assessment.

@lenthomas
Copy link
Member

I think that this is trying to emulate the behaviour of DistWin, where no adjustments are fitted by default in MCDS analyses, but you can manually fit some. I am fine with that as a strategy, so long as it's documented. This would mean that if there's a covariate in the detection function and you don't set nadj or order then you get 0 adjustments; if you specify nadj or order then you get the specified adjustments. I'm also happy with other suggested solutions. Main thing is it's documented clearly in the online help.

I think the error messages are code bugs, aren't they?

@erex
Copy link
Member Author

erex commented May 25, 2023

Right; documentation is inconsistent with code behaviour. Happy for documentation to reflect how code performs. Understand the bug label comes from

Error in covar_fields[i] <- colnames(data)[index] : 
  replacement has length zero

no idea what that means nor how it was triggered. Keep the bug label for that.

@lenthomas
Copy link
Member

Tasks here are to: (1) check the error message that @erex showed in the example above; (2) check that one can ask for adjustment terms using nadj and/or order arguments when there are covariates; (3) check documentation is consistent with this; (4) check mrds package code and documentation also is as above. Looks like current behaviour is not to fit adjustment terms when there are covariates, and this fine, so long as it's documented. All of the above makes behaviour consistent with what DistWin does.

@LHMarshall LHMarshall changed the title ds with covariates and adjustments Error for ds models with covariates and adjustments Nov 24, 2023
LHMarshall added a commit that referenced this issue Dec 14, 2023
Regarding behaviours when there are covariates  in the model in relation to adjustment terms.
@LHMarshall
Copy link
Member

The documentation has been amended and the code above no longer generates an error
image

LHMarshall added a commit that referenced this issue Dec 22, 2023
Regarding behaviours when there are covariates  in the model in relation to adjustment terms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants