Freshwater-Fish-Ecology-Laboratory / detrange

An R package for estimating detection range in passive acoustic telemetry arrays
MIT License
3 stars 0 forks source link

negative predicted distance possible #1

Closed sebdalgarno closed 1 week ago

sebdalgarno commented 2 years ago

Should it be possible to get negative distance estimates from dr_predict_distance()

getting negative e.g. on 0.9 DE on UCR range test data

eogmartins commented 2 years ago

Check out the rivdist package for distance estimates (if you’re trying to compute them in a river network). I used it recently for another project and it worked like a charm.

From: Seb Dalgarno @.> Date: Wednesday, December 8, 2021 at 12:46 To: Freshwater-Fish-Ecology-Laboratory/detrange @.> Cc: Subscribed @.***> Subject: [Freshwater-Fish-Ecology-Laboratory/detrange] negative predicted distance possible (Issue #1) CAUTION: This email is not from UNBC. Avoid links and attachments. Don't buy gift cards.

Should it be possible to get negative distance estimates from dr_predict_distance()

getting negative e.g. on 0.9 DE on UCR range test data

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/Freshwater-Fish-Ecology-Laboratory/detrange/issues/1, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC5XYECL6BD52SZ6XAVCBCTUP673XANCNFSM5JUXY7QA.

sebdalgarno commented 2 years ago

thanks @eogmartins this is for distance in detection range at which a specific level of DE occurs (i.e. 50% midpoint of detection range). I guess the way i calculate the derived parameter it is possible to get a negative distance which cannot be right

here is what my derived expression for one of the models looks like

"for(i in 1:length(Distance)) {
    eIntercept[i] <- bIntercept + bInterceptStation[Station[i]]
    eDistance[i] <- bDistance + bDistanceStation[Station[i]]
    logit(eDetects[i]) <- eIntercept[i] + eDistance[i] * Distance[i]
    target[i] <- eIntercept[i] + (DELogit[i] - eIntercept[i])/eDistance[i]
    prediction[i] <- eDetects[i]
  }"

where target[i] is the estimated distance - from the logit of target DE (i.e. logit(0.5) and the intercept and slope)

sebdalgarno commented 2 years ago

the above model has random slope and random intercept

eogmartins commented 2 years ago

@sebdalgarno I'm not sure I understand how you get the target[i] equation. Can you explain? If you goal is to estimate the distance (target[i]) where detection efficiency is a certain probability (e.g. 0.5 and logit(0.5) = DELogit[i]), then

DELogit[i] = eIntercept[i] + eDistance[i] * target[I]

rearranging

target[i] = (DELogit[i] - eIntercept[i]) / eDistance[i]

Note that distance in target[i] will be in the units input into the model. So if you or a user input centred or standardized distance, the result can have negative values (meaning the estimated distance is shorter than the average of distances).

sebdalgarno commented 2 years ago

@eogmartins thanks! I rearranged incorrectly and i have corrected it in the package. However I still dont think that quite resolves the issue.

Looking at it more closely - here are the observed data and predicted DE from our range test data:

Screen Shot 2021-12-09 at 11 50 47 AM

Take Kinnaird as an example - the estimated intercept by the model is 0.81. So if we ask for the distance at which 0.9 DE occurs it will give a negative distance. I suppose this makes sense.

Should I somehow bound the estimates of distance at 0?

eogmartins commented 2 years ago

Yes, better bound the estimate at zero.

sebdalgarno commented 2 years ago

can this be done somehow in the derived expression?:

 "for(i in 1:length(Distance)) {
    eDistance[i] <- bDistance + bDistanceStation[Station[i]]
    logit(eDetects[i]) <- bIntercept + eDistance[i] * Distance[i]
    target[i] <- (DELogit[i] - bIntercept) / eDistance[i]
    prediction[i] <- eDetects[i]
  }"

or simply by converting any negative values to 0 in the coefficient table? (for estimate, lower and upper values) - this seems hacky