Questions about dsims

23 views
Skip to first unread message

aschi...@gmail.com

unread,
Jul 20, 2022, 2:12:55 PM7/20/22
to distance-sampling
Hi, some questions about dsims


1.  I wonder if it is possible to plot the population generated including the size of each cluster, as it was done previously by Wisps. 

2. Just to check, the histogram made by  histogram.N.ests() can only give the frequency distribution of estimates of clusters, not the estimated population. Am I right?
Because results gives the N estimate at the end as I am working with clusters.

3. When asking for a summary of a simulation, Markdown returns in the console all the text that it usually produces, but the output lacks the numeric results, it returns just the heading (i.e. Estimate sof Abudance). The actual results appears as 9 different data frames.
Surely it is a Markdown issue...

Many thanks






Laura Marshall

unread,
Jul 21, 2022, 3:31:26 AM7/21/22
to aschi...@gmail.com, distance-sampling
Hi Adrian,
Answers inline below
1. I wonder if it is possible to plot the population generated including the size of each cluster, as it was done previously by Wisps.
I'm sure you could... if you generate a survey using the run.survey() function then you can extract the population, that will have the locations and cluster size in it.
survey <- run.survey(simulation)
pop <- survey@population@population # will give you the data.frame that you want
If you come up with a nice plot feel free to send the code over and I can look to incorporate it in the package! 🙂
2. Just to check, the histogram made by histogram.N.ests() can only give the frequency distribution of estimates of clusters, not the estimated population. Am I right?
Because results gives the N estimate at the end as I am working with clusters.
You are in luck! I am busy preparing for a new release and when I took a look at this function I decided that it could do with a wee spruce up so it now has an argument that will allow you to plot either or both and also choose the iterations you would like to include, either only iterations where all models fitted successfully or all iterations where one or more models converged (the same as the summary function). If you install from github you will have access to this improved function now:
devtools::install_github("DistanceDevelopment/dsims")

histogram.N.ests

Description

Plots a histogram of the estimates of abundances

Usage

histogram.N.ests(x, use.max.reps = FALSE, N.ests = "individuals", ...)

Arguments

x

object of class Simulation

use.max.reps

by default this is FALSE meaning that only simulation repetitions where all models converged for that data set are included. By setting this to TRUE any repetition where one or more models converged will be included in the summary results.

N.ests

character indicating whether to plot estimates of abundance of 'individuals', 'clusters' or 'both'. By default this is individuals.

3. When asking for a summary of a simulation, Markdown returns in the console all the text that it usually produces, but the output lacks the numeric results, it returns just the heading (i.e. Estimate sof Abudance). The actual results appears as 9 different data frames.
Surely it is a Markdown issue...
This seems to be how it displays underneath the chunk in the .Rmd file but one you compile to html or pdf it looks as expected, please let me know if it remains an issue in your compiled documents. 

Hope this is of help,
please let me know if you come across any other issues with dsims and I can always put enhancement suggestions on the issue list too!
Best wishes,
Laura

Dr. L Marshall

Centre for Research into Ecological & Environmental Modelling

University of St. Andrews

Tel: +44 (0)1334 461808


Please note that my core working hours are now concentrated between 9am Tuesday and 1pm Thursday. There may be a delay in my response to E-mails outwith these times. 




--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/fa1ad904-6af6-4482-959a-06374cdbc1een%40googlegroups.com.

aschi...@gmail.com

unread,
Jul 21, 2022, 3:58:19 PM7/21/22
to distance-sampling
Dear Laura, many thanks for the update. Happy to be a guinea pig.

I managed to get a plot of the simulated population including  the group size.

For this I used packages tidyverse, sf and ggplot2. 
Surely there are other ways, but I became tidyverse-dependant.

First I get the population object as you mentioned, recovered from the object generated by run.survey()

example <- run.survey(simulation)
pop <- example@population@population 

Then I convert the object from data.frame to tibble, to use it in ggplot2

pop.groups <- as_tibble(pop)

After I use ggplot to 
load the region shapefile "region.shp"  using read_sf

mapa <- read_sf('region.shp')

Then I plot the map using geom_sf() and add the points from the tibble, 
telling ggplot to use x and y as coordinates and the size of the group mapped to size
by "mapping = aes(x = x, y = y, size = size)".
The points are plotted by size and only with the outline.
 "scale_size_continuous(breaks=c(1,2.4,9.6,11.1)" ensures that bins equals the categories established for group size in covariates.
In my case we knew that group size can be defined with four levels with different probabilities:

size.group <- list()
size.group$size <- list(data.frame(level=c(11.1,9.6,2.4,1),prob=c(0.3,0.21,0.16,0.33)))


In the end, the code for plotting  looks like this
ggplot() +
  geom_sf(data = mapa) +
  geom_point(data = pop.groups, mapping = aes(x = x, y = y, size = size),
        shape = 21, colour = "blue", fill = NA) +
  scale_size_continuous(breaks=c(1,2.4,9.6,11.1)) +
  theme(axis.text = element_text(size=11),
        axis.title= element_text(size=12),
        legend.position="top") +
  labs(title="Simulated groups with their size",x = "Long", y = "Latitude", size="Group size")


I attach the resulting map.

Hope it helps
Poblacion guanacos.jpg
Reply all
Reply to author
Forward
0 new messages