problem plotting PDF of detection probability in R

262 views
Skip to first unread message

ej...@st-andrews.ac.uk

unread,
May 12, 2016, 1:37:00 PM5/12/16
to distance-sampling
Good day,
Below are simple histograms of some simulated distance data from point transects.
> par(mfrow = c(1,2))
> hist(trunc.dat, main=NULL, probability=TRUE)
> hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL, probability = TRUE)



Note that when I specify "probability = FALSE", I get the following plot and error message.
>hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL, probability = FALSE)
Warning message:
In plot.histogram(r, freq = freq1, col = col, border = border, angle = angle,  :
  the AREAS in the plot are wrong -- rather use 'freq = FALSE'




When I plot the pdf of detection probability for a model fitted to these data, the histogram looks like the one where the areas are wrong, and the line does not match the data.
>plot(fit.hn, pdf = T)

The simple fix recommended for the histogram doesn't work with plot.ds().
> plot(fit.hn, pdf = T, freq=FALSE)
Error in plot.histogram(hh, ylim = ylim, xlab = xlab, ylab = ylab, main = "",  :
  formal argument "freq" matched by multiple actual arguments


Any ideas why plot.ds is produces a histogram that is apparently wrong behind the line for the fitted pdf, or other ways to produce an accurate plot?

Thanks,
Eric





Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3

David Lawrence Miller

unread,
May 16, 2016, 10:25:13 AM5/16/16
to ej...@st-andrews.ac.uk, distance-sampling
Hi Eric, hi listfolk,

I think there was a bug in how the histogram was rescaled for the point
transect pdf case (it was being rescaled when it didn't need to be).

Eric: can you try out the new version I've just pushed to github and see
whether you get something working? Else please send your example data to
me off-list and I'll take a look and we can report back to the list.

You can install the latest version of mrds using the devtools package:

library(devtools)
install_github("DistanceDevelopment/mrds")

cheers,
--dave


On 12/05/2016 13:37, ej...@st-andrews.ac.uk wrote:
> Good day,
> Below are simple histograms of some simulated distance data from point
> transects.
>> par(mfrow = c(1,2))
>> hist(trunc.dat, main=NULL, probability=TRUE)
>> hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL, probability = TRUE)
>
>
>
> Note that when I specify "probability = FALSE", I get the following plot
> and error message.
>>hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL, probability = FALSE)
> Warning message:
> In plot.histogram(r, freq = freq1, col = col, border = border, angle =
> angle, :
> the AREAS in the plot are wrong -- rather use 'freq = FALSE'
>
>
>
>
> When I plot the pdf of detection probability for a model fitted to these
> data, the histogram looks like the one where the areas are wrong, and
> the line does not match the data.
>>plot(fit.hn, pdf = T)
>
> The simple fix recommended for the histogram doesn't work with plot.ds().
>> plot(fit.hn, pdf = T, freq=FALSE)
> Error in plot.histogram(hh, ylim = ylim, xlab = xlab, ylab = ylab, main
> = "", :
> formal argument "freq" matched by multiple actual arguments
>
> Any ideas why plot.ds is produces a histogram that is apparently wrong
> behind the line for the fitted pdf, or other ways to produce an accurate
> plot?
>
> Thanks,
> Eric
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "distance-sampling" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to distance-sampl...@googlegroups.com
> <mailto:distance-sampl...@googlegroups.com>.
> To post to this group, send email to distance...@googlegroups.com
> <mailto:distance...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/distance-sampling/890a46f6-ff8e-42c9-b142-a9e297060799%40googlegroups.com
> <https://groups.google.com/d/msgid/distance-sampling/890a46f6-ff8e-42c9-b142-a9e297060799%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Eric Howe

unread,
May 16, 2016, 3:19:31 PM5/16/16
to David Lawrence Miller, distance-sampling
Good day list members,
Thank you very much David, that resolved the problem with the bar heights in the histogram. I haven't yet figured out a way to ensure that the line fits in the plot area, since plot.ds() doesn't seem to accept either "ylim" or "add" as arguments. Any ideas welcome!
Eric



Inline images 1

David Lawrence Miller

unread,
May 16, 2016, 4:31:33 PM5/16/16
to Eric Howe, distance-sampling
Hi Eric, hi listfolk,

Glad to hear that worked. I've pushed another change to github fixing
default y axis limits for point transect PDF plotting and allowing you
to set your own values. Let me know if that works for you.

cheers,
--dave



On 16/05/2016 15:19, Eric Howe wrote:
> Good day list members,
> Thank you very much David, that resolved the problem with the bar
> heights in the histogram. I haven't yet figured out a way to ensure that
> the line fits in the plot area, since plot.ds() doesn't seem to accept
> either "ylim" or "add" as arguments. Any ideas welcome!
> Eric
>
>
>
> Inline images 1
>
>
> On 16 May 2016 at 10:25, David Lawrence Miller
> <da...@ninepointeightone.net <mailto:da...@ninepointeightone.net>> wrote:
>
> Hi Eric, hi listfolk,
>
> I think there was a bug in how the histogram was rescaled for the
> point transect pdf case (it was being rescaled when it didn't need
> to be).
>
> Eric: can you try out the new version I've just pushed to github and
> see whether you get something working? Else please send your example
> data to me off-list and I'll take a look and we can report back to
> the list.
>
> You can install the latest version of mrds using the devtools package:
>
> library(devtools)
> install_github("DistanceDevelopment/mrds")
>
> cheers,
> --dave
>
>
> On 12/05/2016 13:37, ej...@st-andrews.ac.uk
> <mailto:ej...@st-andrews.ac.uk> wrote:
>
> Good day,
> Below are simple histograms of some simulated distance data from
> point
> transects.
>
> par(mfrow = c(1,2))
> hist(trunc.dat, main=NULL, probability=TRUE)
> hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL,
> probability = TRUE)
>
>
>
>
> Note that when I specify "probability = FALSE", I get the
> following plot
> and error message.
>
> hist(trunc.dat, breaks = c(1,4,7,10,15), main = NULL,
> probability = FALSE)
>
> Warning message:
> In plot.histogram(r, freq = freq1, col = col, border = border,
> angle =
> angle, :
> the AREAS in the plot are wrong -- rather use 'freq = FALSE'
>
>
>
>
> When I plot the pdf of detection probability for a model fitted
> to these
> data, the histogram looks like the one where the areas are
> wrong, and
> the line does not match the data.
>
> plot(fit.hn <http://fit.hn>, pdf = T)
>
>
> The simple fix recommended for the histogram doesn't work with
> plot.ds().
>
> plot(fit.hn <http://fit.hn>, pdf = T, freq=FALSE)
>
> Error in plot.histogram(hh, ylim = ylim, xlab = xlab, ylab =
> ylab, main
> = "", :
> formal argument "freq" matched by multiple actual arguments
>
> Any ideas why plot.ds is produces a histogram that is apparently
> wrong
> behind the line for the fitted pdf, or other ways to produce an
> accurate
> plot?
>
> Thanks,
> Eric
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "distance-sampling" group.
> To unsubscribe from this group and stop receiving emails from
> it, send
> an email to distance-sampl...@googlegroups.com
> <mailto:distance-sampling%2Bunsu...@googlegroups.com>
> <mailto:distance-sampl...@googlegroups.com
> <mailto:distance-sampling%2Bunsu...@googlegroups.com>>.
> To post to this group, send email to
> distance...@googlegroups.com
> <mailto:distance...@googlegroups.com>
> <mailto:distance...@googlegroups.com

Eric Howe

unread,
May 18, 2016, 1:32:43 PM5/18/16
to David Lawrence Miller, distance-sampling
Dear David and list members,
With the new default settings for ylim in plot.ds(), the probability density curve fit within the plot area. I also tried setting my own ylim values and that worked as well. Much appreciated!
Eric
Reply all
Reply to author
Forward
0 new messages