```{r setup, echo=FALSE} library(knitr) tidy.opts <- list(width.cutoff=50) ``` This document is designed to give you some pointers so that you can perform the Mark-Recapture Distance Sampling practical directly using the mrds package in R, rather than via the Distance visual interface. I assume you have some knowledge of R, the mrds package, and Distance. Golf tee survey ------------------- Luckily for us, the golf tee dataset is provided aspart of the mrds package, so we don't have to worry about obtaining the data from the Distance GolfteesExercise project. Open R and load the mrds library and golf tee dataset. ```{r preliminaries, message=FALSE, comment=NA} library(mrds) data(book.tee.data) #investigate the structure of the dataset str(book.tee.data) #extract the list elements from the dataset into easy-to-use objects detections <- book.tee.data$book.tee.dataframe #make sure sex and exposure are factor variables detections$sex <- as.factor(detections$sex) detections$exposure <- as.factor(detections$exposure) region <- book.tee.data$book.tee.region samples <- book.tee.data$book.tee.samples obs <- book.tee.data$book.tee.obs ``` We'll start by fitting the initial full independence model, with only distance as a covariate. Feel free to use `?` to find out more about any of the functions used -- e.g., `?ddf` will tell you more about the `ddf` function. ```{r, message=FALSE, comment=NA, fig.width=4.5, fig.height=4.5} #Fit the model fi.mr.dist <- ddf(method='trial.fi',mrmodel=~glm(link='logit',formula=~distance), data=detections,meta.data=list(width=4)) #Create a set of tables summarizing the double observer data (this is what Distance does) detection.tables <- det.tables(fi.mr.dist) #Print these detection tables out detection.tables # They could also be plotted, but I've not done so in the interest of space # plot(detection.tables) #Produce a summary of the fitted detection function object summary(fi.mr.dist) #Produce goodness of fit statistics and a qq plot ddf.gof(fi.mr.dist, main="Full independence, trial mode goodness of fit\nGolftee data") #Calculate density estimates using the dht function dht(fi.mr.dist,region,samples,obs) ``` Now, see if you can work out how to change the call to `ddf` to fit the other models mentioned in the exercise, and then write code to enable you to compare the models and select among them.