Amy Whitehead's Research

the ecological musings of a conservation biologist


Leave a comment

New paper – Inside or outside: quantifying extrapolation across river networks

It’s been pretty quiet over here for a long time. But I have been busy beavering away at many interesting projects at NIWA, including a project where we developed a new method for identifying when your regression model is starting to make things up (or more technically, extrapolating beyond the bounds of the dataset).

Regression models are used across the environmental sciences to find patterns between a response and its potential predictors. These patterns can be used to predict a response across broad areas or under new environmental conditions. Our paper compares performance of two flexible regression techniques when predicting across a deliberately induced spectrum of interpolation to extrapolation. Various data sets were divided into two geographical, environmental and random groups. Models were trained on one half of the data and tested on the other. The two methods incorporate nonlinear and interacting relationships but suffer from unquantified uncertainty when extrapolating. Random forests always performed better than multivariate adaptive regression splines when interpolating within environmental space, and when extrapolating in geographical space. Random forests models were transferable in geographic space but not to environmental conditions outside the training data. Neither technique was successful when extrapolating across environmental gradients. The paper also describes and tests a new method to calculate degree of extrapolation: a value quantifying interpolation versus extrapolation for each prediction from either regression technique. The method can be used to indicate risk of spurious predictions when predicting at new locations (e.g., nationally) or under new environmental conditions (e.g., climatic change).

Booker, D.J. & A.L. Whitehead. (2018). Inside or outside: quantifying extrapolation across river networks. Water Resources Research. doi:10.1029/2018WR023378 [online]

Advertisements


3 Comments

Santa’s Little Helper – a function for randomly assigning Secret Santa presents

Christmas can be a stressful and expensive time of year, with many gifts to buy for many people. My family have tried to eliminate some of this stress by having a Secret Santa gifting system where we all buy one present for one member of the family on behalf of everybody else, with a cap of $50 per present.

In our family scheme, there are 3 rules:
1. You can’t give a gift to yourself,
2. You can’t give a gift to your partner (we figure that this will happen anyway),
3. You can’t give a gift to someone you gave one to last year.

Somewhere along the line, I’ve become the designated present-assigner. Now I could write names on pieces of paper and put them in a hat but 1) writing out 11 names is tedious, 2) I don’t have a suitable hat and 3) the rules above mean that there are quite often gifting conflicts arise that require the need for a redraw. So I’ve whipped up a little function in R that does the job. (Admittedly it probably would have been faster to use bits of paper but now I’m prepared for next year).

SantasLittleHelper <- function(myFrame,guestList,conflictCols = NULL){
  myTest <- TRUE
  nElves <- 0

  while (myTest == TRUE){
    myOut <- data.frame(gifter = myFrame[,guestList],
                        giftee = sample(myFrame[,guestList],
                                        replace = FALSE,
                                        size=nrow(myFrame))
                        )

    # check that guests haven't drawn themselves
    guestTest<- unlist(lapply(1:nrow(myOut),function(x) {
      myOut$giftee[x] == myFrame[x,guestList]
      }))

    # check for gifting conflicts
    if(!is.null(conflictCols)){

    conflictTest <- unlist(lapply(1:nrow(myOut),function(x) {
      grepl(myOut$giftee[x],myFrame[x,conflictCols])
      }))

    myTest <- any(c(guestTest,conflictTest[!is.na(conflictTest)]))

    } else{
      myTest <- any(guestTest)
    }

    # count the number of iterations needed to avoid conflicts
    nElves <- nElves + 1
  }

  message(paste(nElves,"elves were needed to generate the gift list"))
  return(myOut)
}

SantasLittleHelper takes three arguments: myFrame is a dataframe containing the list of guests to be assigned gifts; GuestList is the character name of the column containing the list of guests; and conflictCols is an optional character vector of column names that identify gifting conflicts that need to be avoided [1]. The function randomly assigns a giftee to each guest and then checks for conflicts. If conflicts exist, the gifts are reassigned and this continues using a while loop until a suitable solution is found. The function returns a dataframe containing detailing the gifter – giftee combinations, as well as outputting the number of elves (or iterations) needed to generate the list.

To run this for the 2016 Whitehead Family Christmas, I generated a dataframe guests where the column guest lists all of the people coming to Christmas, partner identifies everybody’s significant others and presents2013 lists the assigned giftees from 2013 (the last time we did the Secret Santa thing).

guest partner presents2013
John Fay Jo
Sue Simon Fay
Amy Hamish Sue
Jo Phil Hamish
Ashley Naomi Phil
Naomi Ashley John
Phil Jo Simon
Hamish Amy Naomi
Simon Sue Ashley
Fay John Amy
Zac NA NA

These data are fed into SantasLittleHelper and, bingo, the Whitehead Family Christmas is sorted for another year.

giftList <- SantasLittleHelper(myFrame = guests,
                               guestList = "guest",
                               conflictCols  = c("partner","presents2013")
                               )
27 elves were needed to generate the gift list
gifter giftee
John Zac
Sue Ashley
Amy Phil
Jo Amy
Ashley Fay
Naomi Sue
Phil John
Hamish Jo
Simon Naomi
Fay Simon
Zac Hamish

Hope everyone survives the silly season!

[Merry Christmas everyone!](http://www.r-bloggers.com/merry-christmas-5/)

[1] Technically you could use this feature to rig the outcome to avoid getting a present from Great Aunt Myrtle or Bob from Accounts by adding in an additional conflict column. Use your powers wisely or the ghosts of christmas past may come back to bite you!


Leave a comment

Three new papers: urban development, agriculture & skua

What do urban development, agriculture and skua have in common? Superficially very little, except that they feature in three papers that I published in the past few weeks. These papers are the culmination of  research projects I worked on at Landcare Research and the Quantitative & Applied Ecology group at The University of Melbourne and it’s super exciting to see them finally out in print. Many thanks to the teams of co-authors who made these possible.


Protecting biodiversity while planning for development

987dcdca214651db445aff8e553dfe1c

Clever strategic planning can identify land for urban development that minimises habitat clearing and benefits native plants and animals. Picture: WWF-Australia.

As our cities expand due to population growth, development encroaches on the natural habitat of native plants and animals. While developers often have to assess how their new subdivision or industrial park will impact on these populations, this is usually done at the scale of individual developments and often only considers a few species. The consequence of such ad-hoc assessment is that biodiversity can undergo “death by a thousand cuts” where the cumulative impacts of many development projects can be more severe than those predicted by the individual assessments. However, a lack of good tools and guidance has limited  how impact assessments are carried out. We looked at how existing conservation planning tools can use information on the distribution of many species over large areas to identify the potential impacts of a large-scale development plan in Western Australia. We worked closely with government agencies to identify important areas for biodiversity conservation and make minor changes to the development plans that significantly reduced the potential impacts to biodiversity. See our paper for more details on our framework for undertaking strategic environmental assessments.

Whitehead, A., Kujala, H., & Wintle, B. (2016). Dealing with cumulative biodiversity impacts in strategic environmental assessment: A new frontier for conservation planning Conservation Letters DOI: 10.1111/conl.12260


Can biodiversity, carbon and agricultural development coexist in Australia’s northern savannas?

Irrigated agriculture in the Ord River Development. Developing northern Australia will involve trade-offs with biodiversity. (Image credit: Garry D. Cook)

Irrigated agriculture in the Ord River Development. Developing northern Australia will involve trade-offs with biodiversity. (Image credit: Garry D. Cook)

There’s a lot of talk about developing Australia’s north, of doubling the agricultural output of this region and pouring billions of dollars into new infrastructure such as irrigation. But what about the natural values of this region and its potential for carbon storage today and into the future? Can we develop the north and still retain these other values?  We undertook a spatial analysis which found agricultural development could have profound impacts on biodiversity OR a relatively light impact, it all depends on how and where it’s done. If managers and decision makers want northern Australia’s sweeping northern savannas to serve multiple purposes then they need to plan strategically for them. For more information about how such strategic planning could be done, check out our paper and the associated press release.

Morán-Ordóñez, A., Whitehead, A., Luck, G., Cook, G., Maggini, R., Fitzsimons, J., & Wintle, B. (2016). Analysis of trade-offs between biodiversity, carbon farming and agricultural development in Northern Australia reveals the benefits of strategic planning. Conservation Letters DOI: 10.1111/conl.12255


Counting skua by counting penguins

ed705ca66ee81eb0ac372b523cb85cf0

A skua surveying potential lunch options at the Cape Bird Adélie penguin colony.

South polar skua (Stercorarius maccormicki) like to chow down on penguins. So it makes sense that they often nest close to penguin colonies. Over the years, we’ve developed a pretty good understanding of the size of Adélie penguin (Pygoscelis adeliae) colonies around the Ross Sea, Antarctica, so we set out to see if we could estimate the number of skua associated with those colonies.  Detailed surveys of skua at three Adélie penguin colonies on Ross Island confirmed that more penguins (i.e. more lunch) means more skua.  Using this relationship, we predicted how many skua live in the Ross Sea. To find out how many skua live in the Ross Sea and for a more detailed description of the methods, check out our paper online.

Wilson, D., Lyver, P., Greene, T., Whitehead, A., Dugger, K., Karl, B., Barringer, J., McGarry, R., Pollard, A., & Ainley, D. (2016). South Polar Skua breeding populations in the Ross Sea assessed from demonstrated relationship with Adélie Penguin numbers. Polar Biology. DOI: 10.1007/s00300-016-1980-4


Leave a comment

Extracting raster data using a shapefile

I recently had an email from a PhD student in Austria who had a raster showing the distribution of Douglas Fir in Europe and wanted to know what proportion of each European country was covered in this species. They had a raster with presence (1) and absence (0) of Douglas-fir in Europe and wanted to calculate the number of cells with 1 and 0 within each country of the Europe. I’ve put together a dummy example below which shows how to R script to extract the number of raster cells in each country that meet a certain condition.

fir-drove-1110793_640

Douglas Fir (source: Pixabay)

Essentially the script works through the following steps:

  1. Loads the relevant shapefile and raster datasets.
  2. Identifies all of the countries within the shapefile.
  3. Within a loop, masks the presence-absence raster by each country and counts the number of cells that meet the required condition.

Continue reading


Leave a comment

Goodbye Melbourne, hello (insert adventure here)

As I shut down my laptop for the last time and handed back my office keys a couple of months ago, it was hard to believe that two and a half years earlier, I had packed up my life in shaky Christchurch and moved to Melbourne to start a one year contract with the Quantitative & Applied Ecology group. Like most of the positions in my random career trajectory, I came to Melbourne by (happy) accident. I had applied for a position elsewhere in Australia and didn’t get it. But the guy who interviewed me mentioned this other guy in Melbourne who might have a position. We had a brief chat over the phone which essentially covered “Do you know how to use MaxEnt & Zonation?” & “When can you start?” to which I replied “Sure” & “Soon”.  A month later, I moved to Melbourne to start work with Brendan Wintle. The work has been interesting and varied, although largely concentrating on developing species distribution models to use in real-life conservation planning exercises aimed at informing Strategic Assessments in several regions of Australia. This has included lots of modelling, over a hundred meetings with stakeholders and lots and lots of squinting at maps and swearing at R code.  I also worked with some amazing colleagues, now amazing friends, and generally had a great time in Melbourne. Amazingly, in the two years or so since I started this blog, I have never written about the research I’ve been doing in Melbourne. The QAECO blog has a couple of posts about incorporating social values into conservation planning and some poetry that I wrote about a colleague but, at some point, I should probably remedy that.  But for now, here’s a story about my next adventure….
Not long after I bid my fond farewell to the folks of QAECO, I flew west to Perth to be reunited with my partner of seven years. It had been 4.5 years since we had lived in the same city, so it seemed like it was probably time we did something about that. Since then, I’ve been enjoying the Perth sunshine, finishing up a few work projects and playing travel agent. For we are off on a bike ride.
A big bike ride. Approximately 4,600 km of backcountry bikepacking along the Rocky Mountains from Jasper in Canada to Antelope Wells on the Mexican border. It’s going to be a great adventure and utterly terrifying all at the same time.
The Great Divide
What happens when we get back in November is totally up in the air. While a (tiny) part of me feels that I should be worried about not having a plan (particularly an academic plan) for when we get back. But it is actually quite liberating to just have the open road and endless possibilities ahead.

Needless to say, not much will be happening in this little corner of the web in the next few months but you’ll be able to follow our progress (and tales of bear encounters and other fun stories) at ridingtherockyroad.wordpress.com


1 Comment

Nigel Latta (& me) in Antarctica (on the telly)

Last season, when I was in Antarctica, we had a visit from Nigel Latta, a criminal psychologist turned comedic documentary-maker who makes humorous shows about serious subjects. He was sent to Scott Base, Antarctica to live among the scientists and to discover what life on the Ice is really like and whether it holds the key to our futures. The first episode airs on March 4th at 8:30pm on TV One (in NZ only) and promises to be an entertaining ride.

Filming with Nigel and his team was one of the more entertaining media experiences I’ve had – we defused bombs in a tent, counted (& recounted & recounted & recounted & ….) a constantly moving mass of penguin chicks by trying to name them all, discussed the parenting abilities of penguins and their monogamous (or lack thereof) relationships. I watched (with delight) as Nigel got shat on by a South Polar skua and attacked by angry penguins, we restaged Shackelton’s famous dinner photo and generally had a rollocking good time. I look forward to seeing his thoughts of life On Thin Ice*.

If you miss it (& happen to live in NZ), you should be able to watch it OnDemand.

* Not that I will actually be able to watch it, what with not being in NZ and the restrictions of TV OnDemand….but I’d love to know what you think of it.


8 Comments

Copying files with R

Following on from my recent experience with deleting files using R, I found myself needing to copy a large number of raster files from a folder on my computer to a USB drive so that I could post them to a colleague (yes, snail mail – how old and antiquated!).  While this is not typically a difficult task to do manually, I didn’t want to copy all of the files within the folder and there was no way to sort the folder in a sensible manner that meant I could select out the files that I wanted without individually clicking on all 723 files (out of ~4,300) and copying them over.  Not only would this have been incredibly tedious(!), it’s highly likely that I would have made a mistake and missed something important or copied over files that they didn’t need. So enter my foray into copying files using R. Continue reading