Phylogeny and Species Trait Effects on Detectability

Introduction

This document is a supporting material for the manuscript entitled Phylogeny and species traits predict songbird detectability by Peter Solymos, Steven M. Matsuoka, Diana Stralberg, Erin M. Bayne, and Nicole K. S. Barker.

The lhreg R package contains the (1) data, (2) analysis code used in the manuscript, and (3) code required to summarize the results and produce tables and figures.

The R package is hosted on GitHub, Please submit issues here.

The package is archived on Zenodo under the DOI 10.5281/zenodo.574886.

The package can be installed as:

devtools::install_github("borealbirds/lhreg")

The present document can be viewed as:

vignette(topic = "lhreg", package = "lhreg")

Components of detectability

The manuscript refer to singing rate (SR, here we also refer to it as phi) and detection distance (DD, which we refer to as tau), which are linked to detectability as explained in this section. Solymos et al. (2013, DOI 10.1111/2041-210X.12106) describes the mathematical details of singing rate estimation based on removal sampling and effective detection distance estimation via distance sampling. These quantities define the probability of individuals of the species are available for sampling given presence (often referred to as availability, p), and the probability that an individual of that species is being detected given it produces a cue (often referred to as perceptibility, q).

p = 1 − exp(−t SR), where t is the duration of the counting period. q = DD2 (1 − exp(−r2/DD2)) / r2, where r is the counting radius (i.e. not counting individuals beyond this distance from the observer). Probability of detection is the product to the two components: pq.

Data and data processing

Variables

The lhreg_data is a data frame with all response variables (logphi is log singing rate, logtau is log detection distance) and trait values (unmodified and transformed versions).

library(lhreg)
data(lhreg_data)
str(lhreg_data)
## 'data.frame':    141 obs. of  24 variables:
##  $ spp            : Factor w/ 141 levels "ALFL","AMCR",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ scientific_name: Factor w/ 141 levels "Actitis macularius",..: 37 32 115 5 104 128 116 78 91 50 ...
##  $ common_name    : Factor w/ 141 levels "Alder Flycatcher",..: 1 2 3 4 5 6 8 7 10 9 ...
##  $ WJSpecID       : int  6038 8093 12332 11885 12720 9007 12559 969 10052 13379 ...
##  $ Scientific     : Factor w/ 141 levels "Actitis macularius",..: 51 32 15 5 104 122 110 89 100 62 ...
##  $ Scientific2    : Factor w/ 141 levels "Actitis macularius",..: 51 32 15 5 104 122 110 89 100 62 ...
##  $ logphi         : num  -1.14 -1.36 -2.18 -1.67 -1.17 ...
##  $ logtau         : num  -0.1984 0.6127 -0.2329 0.0905 -0.5379 ...
##  $ logphiSE       : num  0.0147 0.0157 0.0725 0.1209 0.0142 ...
##  $ logtauSE       : num  0.00489 0.00553 0.00456 0.1151 0.00474 ...
##  $ mass           : num  12.7 448.76 12.79 20.68 8.24 ...
##  $ logmass        : num  2.54 6.11 2.55 3.03 2.11 ...
##  $ MaxFreqkHz     : num  6.4 1.62 8.25 8 8 4 6.5 3.2 7 3.9 ...
##  $ Migr           : Factor w/ 4 levels "Neotropical migrant",..: 1 4 4 1 1 4 4 3 1 1 ...
##  $ Nesthm         : num  1 8 2 0 2 2 0 5.6 3 8 ...
##  $ habitat        : Factor w/ 9 levels "Forest","Grassland",..: 7 6 6 2 1 6 6 1 3 6 ...
##  $ food           : Factor w/ 8 levels "Fish","Fruit",..: 3 5 7 3 3 3 7 3 3 3 ...
##  $ behavior       : Factor w/ 8 levels "Aerial Dive",..: 4 6 5 6 5 6 6 3 2 5 ...
##  $ Mig            : Factor w/ 3 levels "LD","WR","SD": 1 3 3 1 1 3 3 2 1 1 ...
##  $ Mig2           : Factor w/ 2 levels "M","W": 1 1 1 1 1 1 1 2 1 1 ...
##  $ Hab2           : Factor w/ 2 levels "Closed","Open": 2 1 1 2 1 1 1 1 2 1 ...
##  $ Hab3           : Factor w/ 3 levels "For","Open","Wood": 2 3 3 2 1 3 3 1 2 3 ...
##  $ Hab4           : Factor w/ 4 levels "For","Open","Wet",..: 2 4 4 2 1 4 4 1 3 4 ...
##  $ xMaxFreqkHz    : num  0.64 0.162 0.825 0.8 0.8 0.4 0.65 0.32 0.7 0.39 ...
with(lhreg_data, plot(exp(logphi), exp(logtau),
    cex=logmass*0.5, col=Mig2, pch=c(21, 22)[Hab2]))
legend("topright", bty="n", pch=c(21, 21, 22, 22), col=c(1,2,1,2),
    legend=c("Migratory/Closed", "Resident/Closed",
    "Migratory/Open", "Resident/Open"))

Here is a list of species used in the manuscript:

common_name scientific_name spp
Alder Flycatcher Empidonax alnorum ALFL
American Crow Corvus brachyrhynchos AMCR
American Goldfinch Spinus tristis AMGO
American Pipit Anthus rubescens AMPI
American Redstart Setophaga ruticilla AMRE
American Robin Turdus migratorius AMRO
American Tree Sparrow Spizella arborea ATSP
American Three-toed Woodpecker Picoides dorsalis ATTW
Bank Swallow Riparia riparia BANS
Baltimore Oriole Icterus galbula BAOR
Barn Swallow Hirundo rustica BARS
Black-and-white Warbler Mniotilta varia BAWW
Black-billed Cuckoo Coccyzus erythropthalmus BBCU
Black-billed Magpie Pica hudsonia BBMA
Bay-breasted Warbler Setophaga castanea BBWA
Black-backed Woodpecker Picoides arcticus BBWO
Black-capped Chickadee Poecile atricapillus BCCH
Belted Kingfisher Megaceryle alcyon BEKI
Brown-headed Cowbird Molothrus ater BHCO
Blue-headed Vireo Vireo solitarius BHVI
Blackburnian Warbler Setophaga fusca BLBW
Blue Jay Cyanocitta cristata BLJA
Blackpoll Warbler Setophaga striata BLPW
Boreal Chickadee Poecile hudsonicus BOCH
Bohemian Waxwing Bombycilla garrulus BOWA
Brewer’s Blackbird Euphagus cyanocephalus BRBL
Brown Creeper Certhia americana BRCR
Brown Thrasher Toxostoma rufum BRTH
Black-throated Blue Warbler Setophaga caerulescens BTBW
Black-throated Green Warbler Setophaga virens BTNW
Blue-winged Warbler Vermivora cyanoptera BWWA
Canada Warbler Cardellina canadensis CAWA
Clay-colored Sparrow Spizella pallida CCSP
Cedar Waxwing Bombycilla cedrorum CEDW
Chipping Sparrow Spizella passerina CHSP
Cliff Swallow Petrochelidon pyrrhonota CLSW
Cape May Warbler Setophaga tigrina CMWA
Common Grackle Quiscalus quiscula COGR
Connecticut Warbler Oporornis agilis CONW
Common Raven Corvus corax CORA
Common Yellowthroat Geothlypis trichas COYE
Chestnut-sided Warbler Setophaga pensylvanica CSWA
Dark-eyed Junco Junco hyemalis DEJU
Downy Woodpecker Picoides pubescens DOWO
Dunlin Calidris alpina DUNL
Eastern Bluebird Sialia sialis EABL
Eastern Kingbird Tyrannus tyrannus EAKI
Eastern Phoebe Sayornis phoebe EAPH
Eastern Towhee Pipilo erythrophthalmus EATO
Eastern Wood-Pewee Contopus virens EAWP
European Starling Sturnus vulgaris EUST
Evening Grosbeak Coccothraustes vespertinus EVGR
Field Sparrow Spizella pusilla FISP
Fox Sparrow Passerella iliaca FOSP
Great Crested Flycatcher Myiarchus crinitus GCFL
Golden-crowned Kinglet Regulus satrapa GCKI
Golden-crowned Sparrow Zonotrichia atricapilla GCSP
Gray-cheeked Thrush Catharus minimus GCTH
Gray Jay Perisoreus canadensis GRAJ
Gray Catbird Dumetella carolinensis GRCA
Greater Yellowlegs Tringa melanoleuca GRYE
Golden-winged Warbler Vermivora chrysoptera GWWA
Hammond’s Flycatcher Empidonax hammondii HAFL
Hairy Woodpecker Picoides villosus HAWO
Hermit Thrush Catharus guttatus HETH
Horned Lark Eremophila alpestris HOLA
House Sparrow Passer domesticus HOSP
House Wren Troglodytes aedon HOWR
Indigo Bunting Passerina cyanea INBU
Killdeer Charadrius vociferus KILL
Lapland Longspur Calcarius lapponicus LALO
Le Conte’s Sparrow Ammodramus leconteii LCSP
Least Flycatcher Empidonax minimus LEFL
Lesser Yellowlegs Tringa flavipes LEYE
Lincoln’s Sparrow Melospiza lincolnii LISP
Magnolia Warbler Setophaga magnolia MAWA
Marsh Wren Cistothorus palustris MAWR
Mountain Bluebird Sialia currucoides MOBL
Mourning Dove Zenaida macroura MODO
Mourning Warbler Geothlypis philadelphia MOWA
Nashville Warbler Oreothlypis ruficapilla NAWA
Nelson’s Sparrow Ammodramus nelsoni NESP
Northern Flicker Colaptes auratus NOFL
Northern Parula Setophaga americana NOPA
Northern Waterthrush Parkesia noveboracensis NOWA
Orange-crowned Warbler Oreothlypis celata OCWA
Olive-sided Flycatcher Contopus cooperi OSFL
Ovenbird Seiurus aurocapilla OVEN
Palm Warbler Setophaga palmarum PAWA
Philadelphia Vireo Vireo philadelphicus PHVI
Pine Grosbeak Pinicola enucleator PIGR
Pine Siskin Spinus pinus PISI
Pine Warbler Setophaga pinus PIWA
Pileated Woodpecker Dryocopus pileatus PIWO
Purple Finch Carpodacus purpureus PUFI
Rose-breasted Grosbeak Pheucticus ludovicianus RBGR
Red-breasted Nuthatch Sitta canadensis RBNU
Ruby-crowned Kinglet Regulus calendula RCKI
Red Crossbill Loxia curvirostra RECR
Red-eyed Vireo Vireo olivaceus REVI
Rock Sandpiper Calidris ptilocnemis ROSA
Ruby-throated Hummingbird Archilochus colubris RTHU
Rusty Blackbird Euphagus carolinus RUBL
Ruffed Grouse Bonasa umbellus RUGR
Red-winged Blackbird Agelaius phoeniceus RWBL
Savannah Sparrow Passerculus sandwichensis SAVS
Scarlet Tanager Piranga olivacea SCTA
Sedge Wren Cistothorus platensis SEWR
Solitary Sandpiper Tringa solitaria SOSA
Song Sparrow Melospiza melodia SOSP
Spruce Grouse Falcipennis canadensis SPGR
Spotted Sandpiper Actitis macularius SPSA
Swamp Sparrow Melospiza georgiana SWSP
Swainson’s Thrush Catharus ustulatus SWTH
Tennessee Warbler Oreothlypis peregrina TEWA
Townsend’s Solitaire Myadestes townsendi TOSO
Townsend’s Warbler Setophaga townsendi TOWA
Tree Swallow Tachycineta bicolor TRES
Upland Sandpiper Bartramia longicauda UPSA
Varied Thrush Ixoreus naevius VATH
Veery Catharus fuscescens VEER
Vesper Sparrow Pooecetes gramineus VESP
Warbling Vireo Vireo gilvus WAVI
White-breasted Nuthatch Sitta carolinensis WBNU
White-crowned Sparrow Zonotrichia leucophrys WCSP
Western Tanager Piranga ludoviciana WETA
Western Wood-Pewee Contopus sordidulus WEWP
Willow Ptarmigan Lagopus lagopus WIPT
Wilson’s Snipe Gallinago delicata WISN
Wilson’s Warbler Cardellina pusilla WIWA
Winter Wren Troglodytes hiemalis WIWR
Wood Thrush Hylocichla mustelina WOTH
White-throated Sparrow Zonotrichia albicollis WTSP
White-winged Crossbill Loxia leucoptera WWCR
Yellow-billed Cuckoo Coccyzus americanus YBCU
Yellow-bellied Flycatcher Empidonax flaviventris YBFL
Yellow-bellied Sapsucker Sphyrapicus varius YBSA
Yellow Warbler Setophaga petechia YEWA
Yellow-headed Blackbird Xanthocephalus xanthocephalus YHBL
Yellow-rumped Warbler Setophaga coronata YRWA
Yellow-throated Vireo Vireo flavifrons YTVI

Here are the response variables and their standard errors:

common_name SR logphi logphiSE DD logtau logtauSE
Alder Flycatcher 0.320 -1.138 0.015 82.006 -0.198 0.005
American Crow 0.257 -1.358 0.016 184.538 0.613 0.006
American Goldfinch 0.114 -2.175 0.073 79.222 -0.233 0.005
American Pipit 0.189 -1.669 0.121 109.467 0.090 0.115
American Redstart 0.311 -1.169 0.014 58.398 -0.538 0.005
American Robin 0.233 -1.456 0.013 93.723 -0.065 0.003
American Tree Sparrow 0.239 -1.430 0.042 96.194 -0.039 0.037
American Three-toed Woodpecker 0.157 -1.852 0.119 83.733 -0.178 0.024
Bank Swallow 0.207 -1.573 0.141 104.713 0.046 0.009
Baltimore Oriole 0.223 -1.502 0.078 83.612 -0.179 0.010
Barn Swallow 0.126 -2.072 0.176 91.939 -0.084 0.006
Black-and-white Warbler 0.244 -1.411 0.019 61.796 -0.481 0.006
Black-billed Cuckoo 0.126 -2.075 0.146 129.832 0.261 0.026
Black-billed Magpie 0.231 -1.464 0.045 201.149 0.699 0.091
Bay-breasted Warbler 0.293 -1.226 0.030 40.285 -0.909 0.009
Black-backed Woodpecker 0.197 -1.624 0.102 73.152 -0.313 0.025
Black-capped Chickadee 0.170 -1.773 0.024 69.245 -0.368 0.004
Belted Kingfisher 0.066 -2.714 0.501 101.418 0.014 0.024
Brown-headed Cowbird 0.204 -1.588 0.031 70.703 -0.347 0.007
Blue-headed Vireo 0.220 -1.514 0.029 67.926 -0.387 0.007
Blackburnian Warbler 0.269 -1.312 0.020 58.645 -0.534 0.008
Blue Jay 0.157 -1.853 0.021 123.055 0.207 0.005
Blackpoll Warbler 0.263 -1.336 0.065 47.355 -0.747 0.015
Boreal Chickadee 0.139 -1.974 0.059 44.585 -0.808 0.010
Bohemian Waxwing 0.055 -2.892 0.595 50.822 -0.677 0.036
Brewer’s Blackbird 0.282 -1.265 0.065 109.238 0.088 0.037
Brown Creeper 0.180 -1.713 0.039 49.242 -0.708 0.009
Brown Thrasher 0.284 -1.259 0.067 108.198 0.079 0.019
Black-throated Blue Warbler 0.243 -1.414 0.049 69.802 -0.360 0.008
Black-throated Green Warbler 0.287 -1.247 0.014 72.827 -0.317 0.004
Blue-winged Warbler 0.234 -1.452 0.148 60.032 -0.510 0.056
Canada Warbler 0.300 -1.204 0.022 62.876 -0.464 0.009
Clay-colored Sparrow 0.462 -0.772 0.015 62.238 -0.474 0.011
Cedar Waxwing 0.114 -2.169 0.058 63.010 -0.462 0.006
Chipping Sparrow 0.282 -1.267 0.012 70.107 -0.355 0.003
Cliff Swallow 0.226 -1.485 0.127 76.801 -0.264 0.017
Cape May Warbler 0.276 -1.287 0.036 42.780 -0.849 0.014
Common Grackle 0.225 -1.493 0.129 89.164 -0.115 0.004
Connecticut Warbler 0.431 -0.843 0.030 70.520 -0.349 0.007
Common Raven 0.193 -1.642 0.024 155.587 0.442 0.009
Common Yellowthroat 0.309 -1.174 0.014 83.614 -0.179 0.005
Chestnut-sided Warbler 0.297 -1.215 0.011 78.740 -0.239 0.005
Dark-eyed Junco 0.222 -1.504 0.017 68.121 -0.384 0.004
Downy Woodpecker 0.109 -2.221 0.100 75.998 -0.274 0.013
Dunlin 0.086 -2.459 0.839 133.989 0.293 0.122
Eastern Bluebird 0.071 -2.649 0.522 86.761 -0.142 0.027
Eastern Kingbird 0.244 -1.412 0.081 84.235 -0.172 0.010
Eastern Phoebe 0.186 -1.682 0.135 92.117 -0.082 0.015
Eastern Towhee 0.271 -1.307 0.046 97.063 -0.030 0.024
Eastern Wood-Pewee 0.306 -1.184 0.019 113.558 0.127 0.010
European Starling 0.327 -1.118 0.068 106.409 0.062 0.003
Evening Grosbeak 0.121 -2.116 0.112 79.757 -0.226 0.016
Field Sparrow 0.183 -1.701 0.156 123.472 0.211 0.021
Fox Sparrow 0.212 -1.552 0.037 118.792 0.172 0.015
Great Crested Flycatcher 0.168 -1.785 0.051 111.781 0.111 0.009
Golden-crowned Kinglet 0.201 -1.606 0.030 42.337 -0.860 0.008
Golden-crowned Sparrow 0.201 -1.605 0.125 126.875 0.238 0.080
Gray-cheeked Thrush 0.214 -1.540 0.083 95.460 -0.046 0.025
Gray Jay 0.152 -1.884 0.026 68.387 -0.380 0.006
Gray Catbird 0.213 -1.548 0.062 77.834 -0.251 0.012
Greater Yellowlegs 0.256 -1.363 0.053 105.813 0.057 0.022
Golden-winged Warbler 0.214 -1.540 0.058 78.960 -0.236 0.029
Hammond’s Flycatcher 0.281 -1.270 0.083 51.427 -0.665 0.021
Hairy Woodpecker 0.133 -2.016 0.063 72.297 -0.324 0.010
Hermit Thrush 0.323 -1.131 0.009 103.884 0.038 0.004
Horned Lark 0.492 -0.709 0.020 96.165 -0.039 0.014
House Sparrow 0.448 -0.803 0.054 83.446 -0.181 0.007
House Wren 0.418 -0.873 0.024 90.529 -0.099 0.011
Indigo Bunting 0.240 -1.427 0.045 91.039 -0.094 0.012
Killdeer 0.215 -1.535 0.065 108.961 0.086 0.011
Lapland Longspur 0.302 -1.197 0.109 80.618 -0.215 0.026
Le Conte’s Sparrow 0.588 -0.531 0.035 65.010 -0.431 0.017
Least Flycatcher 0.417 -0.874 0.010 59.191 -0.524 0.004
Lesser Yellowlegs 0.165 -1.800 0.078 127.868 0.246 0.022
Lincoln’s Sparrow 0.305 -1.186 0.018 70.078 -0.356 0.006
Magnolia Warbler 0.280 -1.274 0.015 63.650 -0.452 0.004
Marsh Wren 0.376 -0.979 0.118 82.367 -0.194 0.039
Mountain Bluebird 0.221 -1.509 0.298 32.282 -1.131 0.070
Mourning Dove 0.234 -1.453 0.049 106.783 0.066 0.006
Mourning Warbler 0.300 -1.204 0.016 66.992 -0.401 0.005
Nashville Warbler 0.335 -1.095 0.008 79.270 -0.232 0.004
Nelson’s Sparrow 0.260 -1.348 0.163 87.756 -0.131 0.100
Northern Flicker 0.122 -2.106 0.052 108.218 0.079 0.008
Northern Parula 0.236 -1.443 0.029 75.542 -0.280 0.012
Northern Waterthrush 0.252 -1.380 0.029 93.509 -0.067 0.009
Orange-crowned Warbler 0.205 -1.586 0.035 63.042 -0.461 0.011
Olive-sided Flycatcher 0.281 -1.271 0.042 103.299 0.032 0.015
Ovenbird 0.387 -0.949 0.005 87.886 -0.129 0.002
Palm Warbler 0.336 -1.091 0.021 60.507 -0.502 0.009
Philadelphia Vireo 0.347 -1.058 0.052 59.176 -0.525 0.010
Pine Grosbeak 0.099 -2.312 0.305 76.915 -0.262 0.034
Pine Siskin 0.174 -1.750 0.035 50.350 -0.686 0.008
Pine Warbler 0.239 -1.433 0.032 88.971 -0.117 0.012
Pileated Woodpecker 0.122 -2.102 0.063 137.597 0.319 0.014
Purple Finch 0.110 -2.203 0.101 74.682 -0.292 0.013
Rose-breasted Grosbeak 0.256 -1.364 0.016 89.651 -0.109 0.005
Red-breasted Nuthatch 0.160 -1.833 0.026 78.936 -0.237 0.005
Ruby-crowned Kinglet 0.286 -1.251 0.013 78.320 -0.244 0.004
Red Crossbill 0.261 -1.345 0.104 58.916 -0.529 0.032
Red-eyed Vireo 0.377 -0.976 0.006 85.637 -0.155 0.002
Rock Sandpiper 0.233 -1.457 0.172 136.519 0.311 0.068
Ruby-throated Hummingbird 0.060 -2.822 0.363 46.531 -0.765 0.032
Rusty Blackbird 0.157 -1.852 0.117 83.421 -0.181 0.027
Ruffed Grouse 0.274 -1.295 0.031 99.020 -0.010 0.010
Red-winged Blackbird 0.394 -0.931 0.016 97.989 -0.020 0.003
Savannah Sparrow 0.467 -0.762 0.013 91.330 -0.091 0.006
Scarlet Tanager 0.192 -1.648 0.034 102.820 0.028 0.013
Sedge Wren 0.286 -1.253 0.085 96.805 -0.032 0.043
Solitary Sandpiper 0.099 -2.309 0.169 83.096 -0.185 0.029
Song Sparrow 0.291 -1.234 0.021 88.024 -0.128 0.004
Spruce Grouse 0.224 -1.495 0.235 47.933 -0.735 0.055
Spotted Sandpiper 0.176 -1.734 0.101 95.297 -0.048 0.029
Swamp Sparrow 0.251 -1.382 0.029 83.775 -0.177 0.008
Swainson’s Thrush 0.327 -1.119 0.009 83.893 -0.176 0.003
Tennessee Warbler 0.451 -0.797 0.008 59.540 -0.519 0.003
Townsend’s Solitaire 0.123 -2.093 0.353 44.970 -0.799 0.027
Townsend’s Warbler 0.123 -2.092 0.144 70.887 -0.344 0.022
Tree Swallow 0.227 -1.482 0.055 93.982 -0.062 0.007
Upland Sandpiper 0.164 -1.811 0.120 141.986 0.351 0.039
Varied Thrush 0.252 -1.380 0.034 101.896 0.019 0.011
Veery 0.265 -1.327 0.013 101.160 0.012 0.005
Vesper Sparrow 0.532 -0.630 0.017 114.315 0.134 0.020
Warbling Vireo 0.333 -1.099 0.028 74.126 -0.299 0.008
White-breasted Nuthatch 0.150 -1.900 0.058 79.684 -0.227 0.014
White-crowned Sparrow 0.266 -1.326 0.023 106.838 0.066 0.013
Western Tanager 0.290 -1.240 0.026 73.146 -0.313 0.007
Western Wood-Pewee 0.306 -1.184 0.049 72.781 -0.318 0.016
Willow Ptarmigan 0.057 -2.863 0.514 177.379 0.573 0.158
Wilson’s Snipe 0.281 -1.270 0.021 122.850 0.206 0.010
Wilson’s Warbler 0.254 -1.370 0.032 60.642 -0.500 0.012
Winter Wren 0.348 -1.056 0.014 95.182 -0.049 0.004
Wood Thrush 0.305 -1.187 0.038 119.083 0.175 0.013
White-throated Sparrow 0.301 -1.200 0.007 92.758 -0.075 0.002
White-winged Crossbill 0.129 -2.050 0.052 68.731 -0.375 0.008
Yellow-billed Cuckoo 0.155 -1.866 0.176 107.157 0.069 0.069
Yellow-bellied Flycatcher 0.272 -1.301 0.021 72.750 -0.318 0.007
Yellow-bellied Sapsucker 0.155 -1.866 0.024 86.465 -0.145 0.005
Yellow Warbler 0.329 -1.112 0.020 69.862 -0.359 0.005
Yellow-headed Blackbird 0.441 -0.819 0.055 88.653 -0.120 0.104
Yellow-rumped Warbler 0.287 -1.248 0.008 59.107 -0.526 0.002
Yellow-throated Vireo 0.199 -1.612 0.062 85.886 -0.152 0.042

Other trait variables used are predictors:

common_name mass MaxFreqkHz Mig2 Hab2 Nesthm
Alder Flycatcher 12.70 6.40 M Open 1.0
American Crow 448.76 1.62 M Closed 8.0
American Goldfinch 12.79 8.25 M Closed 2.0
American Pipit 20.68 8.00 M Open 0.0
American Redstart 8.24 8.00 M Closed 2.0
American Robin 78.50 4.00 M Closed 2.0
American Tree Sparrow 17.83 6.50 M Closed 0.0
American Three-toed Woodpecker 55.05 3.20 W Closed 5.6
Bank Swallow 12.68 7.00 M Open 3.0
Baltimore Oriole 32.83 3.90 M Closed 8.0
Barn Swallow 17.91 7.00 M Open 2.0
Black-and-white Warbler 10.90 9.00 M Closed 0.0
Black-billed Cuckoo 50.90 2.50 M Closed 1.0
Black-billed Magpie 217.48 6.00 W Closed 4.0
Bay-breasted Warbler 11.80 9.00 M Closed 4.0
Black-backed Woodpecker 69.24 12.00 W Closed 4.0
Black-capped Chickadee 10.80 3.20 W Closed 2.0
Belted Kingfisher 148.00 9.00 M Open 4.0
Brown-headed Cowbird 40.26 12.00 M Open 2.0
Blue-headed Vireo 15.30 6.00 M Closed 3.0
Blackburnian Warbler 9.74 11.50 M Closed 9.0
Blue Jay 88.00 3.20 W Closed 4.0
Blackpoll Warbler 11.84 10.22 M Closed 2.0
Boreal Chickadee 9.80 7.70 W Closed 3.0
Bohemian Waxwing 54.41 10.00 W Closed 8.0
Brewer’s Blackbird 62.48 6.70 M Open 0.0
Brown Creeper 8.10 8.50 W Closed 3.0
Brown Thrasher 68.80 6.50 M Open 1.0
Black-throated Blue Warbler 10.14 6.00 M Closed 0.0
Black-throated Green Warbler 8.69 8.00 M Closed 5.0
Blue-winged Warbler 8.90 6.80 M Closed 0.0
Canada Warbler 10.04 7.39 M Closed 0.0
Clay-colored Sparrow 11.20 5.50 M Open 1.0
Cedar Waxwing 31.58 8.50 M Closed 2.0
Chipping Sparrow 12.20 5.98 M Closed 2.0
Cliff Swallow 21.60 7.00 M Open 4.0
Cape May Warbler 10.04 8.65 M Closed 11.0
Common Grackle 105.18 4.00 M Closed 3.0
Connecticut Warbler 13.30 16.00 M Closed 0.0
Common Raven 927.97 4.00 W Open 17.0
Common Yellowthroat 9.54 6.30 M Open 0.0
Chestnut-sided Warbler 9.29 7.50 M Closed 1.0
Dark-eyed Junco 19.50 8.20 M Closed 0.0
Downy Woodpecker 25.55 4.25 W Closed 6.0
Dunlin 51.89 3.50 M Open 0.0
Eastern Bluebird 27.50 3.50 M Open 3.0
Eastern Kingbird 39.85 8.20 M Open 3.0
Eastern Phoebe 19.70 5.00 M Closed 2.0
Eastern Towhee 40.03 9.00 M Open 1.5
Eastern Wood-Pewee 13.90 5.00 M Closed 7.0
European Starling 77.14 6.00 M Open 6.0
Evening Grosbeak 57.30 4.20 W Closed 12.0
Field Sparrow 12.50 4.10 M Open 1.0
Fox Sparrow 33.25 7.00 M Closed 0.0
Great Crested Flycatcher 32.10 3.50 M Closed 3.0
Golden-crowned Kinglet 6.19 9.50 M Closed 10.0
Golden-crowned Sparrow 31.99 5.50 M Open 0.0
Gray-cheeked Thrush 31.58 7.50 M Closed 2.0
Gray Jay 71.58 1.80 W Closed 4.0
Gray Catbird 35.30 9.00 M Closed 1.0
Greater Yellowlegs 161.74 3.45 M Open 0.0
Golden-winged Warbler 8.74 8.50 M Closed 0.0
Hammond’s Flycatcher 10.44 7.00 M Closed 8.0
Hairy Woodpecker 62.65 5.50 W Closed 8.0
Hermit Thrush 30.10 6.50 M Closed 0.0
Horned Lark 33.33 7.00 M Open 0.0
House Sparrow 26.51 5.00 W Open 4.0
House Wren 10.85 8.00 M Closed 2.0
Indigo Bunting 14.69 8.00 M Closed 1.0
Killdeer 96.44 2.58 M Open 0.0
Lapland Longspur 27.84 5.00 M Open 0.0
Le Conte’s Sparrow 13.00 11.00 M Open 0.0
Least Flycatcher 10.00 7.50 M Closed 6.0
Lesser Yellowlegs 77.50 2.79 M Open 0.0
Lincoln’s Sparrow 16.60 7.00 M Open 0.0
Magnolia Warbler 8.14 7.50 M Closed 1.0
Marsh Wren 10.80 9.00 M Open 1.0
Mountain Bluebird 29.60 3.00 M Closed 8.0
Mourning Dove 118.93 0.47 M Closed 2.0
Mourning Warbler 11.74 5.46 M Closed 0.0
Nashville Warbler 8.09 9.25 M Closed 0.0
Nelson’s Sparrow 15.11 7.30 M Open 0.0
Northern Flicker 131.46 3.35 M Closed 7.0
Northern Parula 7.84 8.00 M Closed 9.0
Northern Waterthrush 16.30 9.00 M Closed 0.0
Orange-crowned Warbler 9.19 8.50 M Closed 0.0
Olive-sided Flycatcher 32.10 3.80 M Closed 8.0
Ovenbird 18.80 8.00 M Closed 0.0
Palm Warbler 10.30 8.00 M Closed 0.0
Philadelphia Vireo 11.50 7.00 M Closed 9.0
Pine Grosbeak 56.40 4.50 W Closed 4.0
Pine Siskin 12.70 8.00 M Closed 5.0
Pine Warbler 11.79 5.70 M Closed 12.0
Pileated Woodpecker 286.59 6.00 W Closed 10.0
Purple Finch 23.30 6.00 M Closed 4.0
Rose-breasted Grosbeak 42.00 9.00 M Closed 3.0
Red-breasted Nuthatch 9.80 8.00 W Closed 6.0
Ruby-crowned Kinglet 6.19 7.00 M Closed 5.0
Red Crossbill 38.29 6.00 W Closed 8.0
Red-eyed Vireo 16.06 6.00 M Closed 2.0
Rock Sandpiper 81.32 7.00 M Open 0.0
Ruby-throated Hummingbird 3.09 6.00 M Closed 4.0
Rusty Blackbird 59.57 9.50 M Closed 1.0
Ruffed Grouse 530.91 4.00 W Closed 0.0
Red-winged Blackbird 50.78 6.00 M Open 1.0
Savannah Sparrow 19.97 10.00 M Open 0.0
Scarlet Tanager 28.20 5.00 M Closed 6.0
Sedge Wren 9.04 7.80 M Open 0.0
Solitary Sandpiper 48.40 5.80 M Open 7.0
Song Sparrow 21.91 9.00 M Closed 0.0
Spruce Grouse 473.65 6.00 W Closed 0.0
Spotted Sandpiper 40.40 5.43 M Open 0.0
Swamp Sparrow 16.10 7.66 M Open 2.0
Swainson’s Thrush 30.30 6.05 M Closed 2.0
Tennessee Warbler 8.90 10.00 M Closed 0.0
Townsend’s Solitaire 33.20 5.50 M Closed 0.0
Townsend’s Warbler 8.84 8.20 M Closed 11.0
Tree Swallow 21.20 5.95 M Open 4.0
Upland Sandpiper 158.92 4.00 M Open 0.0
Varied Thrush 77.50 5.85 M Closed 6.0
Veery 31.90 5.60 M Closed 0.0
Vesper Sparrow 25.68 6.85 M Open 0.0
Warbling Vireo 12.67 6.90 M Closed 8.0
White-breasted Nuthatch 21.00 2.90 W Closed 5.0
White-crowned Sparrow 28.00 7.00 M Open 1.0
Western Tanager 28.10 4.42 M Closed 11.0
Western Wood-Pewee 13.10 5.25 M Closed 8.0
Willow Ptarmigan 566.86 7.00 W Open 0.0
Wilson’s Snipe 112.94 2.40 M Open 0.0
Wilson’s Warbler 6.96 8.10 M Open 0.0
Winter Wren 9.74 9.00 M Closed 1.0
Wood Thrush 50.09 4.43 M Closed 2.0
White-throated Sparrow 24.40 6.60 M Closed 0.0
White-winged Crossbill 28.69 6.20 W Closed 12.0
Yellow-billed Cuckoo 64.00 0.90 M Closed 2.0
Yellow-bellied Flycatcher 11.80 4.00 M Closed 0.0
Yellow-bellied Sapsucker 50.30 2.41 M Closed 8.0
Yellow Warbler 10.22 6.75 M Closed 1.0
Yellow-headed Blackbird 62.68 7.30 M Open 0.0
Yellow-rumped Warbler 11.94 5.80 M Closed 4.0
Yellow-throated Vireo 18.00 5.00 M Closed 12.0

Phylogenetic correlations

This code was used to average the 1000 pseudo-posterior trees from Jetz et al. (2012) with Ericson backbone to represent the phylogenetic relationships among the species:

library(ape)
mph <- read.nexus("11960.tre") # 1000 trees with Ericson backbone
lhreg_tree <- consensus(mph)
table(sapply(mph, function(z) length(z$tip.label)))
CORR <- TRUE
vv <- list()
vv[[1]] <- vcv(mph[[1]], corr=CORR)
for (i in 2:length(mph)) {
    v <- vcv(mph[[i]], corr=CORR)
    v <- v[rownames(vv[[1]]), colnames(vv[[1]])]
    vv[[i]] <- v
}
vvv <- v
for (i in 1:length(v)) {
    vvv[i] <- mean(sapply(vv, function(z) z[i]))
}
spp <- intersect(rownames(lhreg_data), rownames(vvv))
vvv <- vvv[spp,spp]
cor_matrix <- as.matrix(nearPD(vvv, corr=TRUE)$mat)

The object cor_matrix is part of the lhreg package, relative phylogenies can be reconstructed from it:

library(ape)
data(cor_matrix)
data(lhreg_tree)
## Warning in data(lhreg_tree): data set 'lhreg_tree' not found
str(cor_matrix)
##  num [1:141, 1:141] 1 0.33 0.33 0.33 0.33 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : chr [1:141] "Empidonax_alnorum" "Corvus_brachyrhynchos" "Carduelis_tristis" "Anthus_rubescens" ...
##   ..$ : chr [1:141] "Empidonax_alnorum" "Corvus_brachyrhynchos" "Carduelis_tristis" "Anthus_rubescens" ...
heatmap(cor_matrix)

Analysis

Linear model were used to screen trait variables, so that we compared that full model with the intercept only null model, with or without phylogenetic correlation.

Variable screening for SR

library(lhreg)
data(lhreg_data)
data(cor_matrix)

y <- lhreg_data$logphi
m4 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab4, lhreg_data)
m3 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab3, lhreg_data)
m2 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2, lhreg_data)
m4s <- step(m4, trace=0)
m3s <- step(m3, trace=0)
m2s <- step(m2, trace=0)
AIC(m4,m3,m2,m4s,m3s,m2s)
##     df      AIC
## m4   9 159.2927
## m3   8 159.9963
## m2   7 159.5903
## m4s  5 157.4045
## m3s  5 157.4045
## m2s  5 157.4045
summary(m2s)
## 
## Call:
## lm(formula = y ~ Mig2 + Nesthm + xMaxFreqkHz, data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.35699 -0.17658  0.05151  0.23901  1.06279 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.60265    0.11180  -14.34  < 2e-16 ***
## Mig2W       -0.36778    0.09966   -3.69 0.000322 ***
## Nesthm      -0.01553    0.01022   -1.52 0.130918    
## xMaxFreqkHz  0.33360    0.14825    2.25 0.026031 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.414 on 137 degrees of freedom
## Multiple R-squared:  0.1833, Adjusted R-squared:  0.1654 
## F-statistic: 10.25 on 3 and 137 DF,  p-value: 3.916e-06
mp <- update(m2s, .~.-Nesthm)

amp <- anova(mp)
round(structure(100 * amp[,"Sum Sq"] / sum(amp[,"Sum Sq"]),
    names=rownames(amp)), 1)
##        Mig2 xMaxFreqkHz   Residuals 
##        13.4         3.6        83.0
mp0 <- lm(y ~ 1)
summary(mp0) # null model for SR
## 
## Call:
## lm(formula = y ~ 1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.39617 -0.23821  0.06881  0.28168  0.96531 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.49625    0.03817   -39.2   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4532 on 140 degrees of freedom
summary(mp) # full model for SR
## 
## Call:
## lm(formula = y ~ Mig2 + xMaxFreqkHz, data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.37585 -0.18443  0.05156  0.26123  1.08980 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.6619     0.1053 -15.783  < 2e-16 ***
## Mig2W        -0.4108     0.0960  -4.280 3.48e-05 ***
## xMaxFreqkHz   0.3599     0.1479   2.432   0.0163 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.416 on 138 degrees of freedom
## Multiple R-squared:  0.1696, Adjusted R-squared:  0.1575 
## F-statistic: 14.09 on 2 and 138 DF,  p-value: 2.705e-06
## evaluating interactions
mpx <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 +
    logmass:xMaxFreqkHz + Hab2:xMaxFreqkHz, lhreg_data)
mpx2 <- step(mpx)
## Start:  AIC=-248.78
## y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 + logmass:xMaxFreqkHz + 
##     Hab2:xMaxFreqkHz
## 
##                       Df Sum of Sq    RSS     AIC
## <none>                             21.561 -248.78
## - xMaxFreqkHz:Hab2     1   0.32411 21.886 -248.67
## - Nesthm               1   0.49472 22.056 -247.58
## - Mig2                 1   0.99609 22.558 -244.41
## - logmass:xMaxFreqkHz  1   1.49463 23.056 -241.33
summary(mpx2)
## 
## Call:
## lm(formula = y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 + 
##     logmass:xMaxFreqkHz + Hab2:xMaxFreqkHz, data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.42164 -0.17969  0.02572  0.24807  1.03521 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          -2.28929    0.37591  -6.090 1.14e-08 ***
## logmass               0.21429    0.09721   2.204  0.02922 *  
## Mig2W                -0.26467    0.10677  -2.479  0.01444 *  
## Nesthm               -0.01806    0.01034  -1.747  0.08297 .  
## xMaxFreqkHz           1.73042    0.54335   3.185  0.00181 ** 
## Hab2Open             -0.24608    0.23044  -1.068  0.28751    
## logmass:xMaxFreqkHz  -0.47046    0.15494  -3.036  0.00288 ** 
## xMaxFreqkHz:Hab2Open  0.47503    0.33596   1.414  0.15972    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4026 on 133 degrees of freedom
## Multiple R-squared:  0.2502, Adjusted R-squared:  0.2107 
## F-statistic: 6.339 on 7 and 133 DF,  p-value: 1.962e-06

Variable screening for DD

y <- lhreg_data$logtau
m4 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab4, lhreg_data)
m3 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab3, lhreg_data)
m2 <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2, lhreg_data)
m4s <- step(m4, trace=0)
m3s <- step(m3, trace=0)
m2s <- step(m2, trace=0)
AIC(m4,m3,m2,m4s,m3s,m2s)
##     df      AIC
## m4   9 -1.18506
## m3   8 -3.17346
## m2   7 -5.16348
## m4s  9 -1.18506
## m3s  8 -3.17346
## m2s  7 -5.16348
summary(m2s)
## 
## Call:
## lm(formula = y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2, 
##     data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.97677 -0.11551 -0.00027  0.15237  0.71312 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.557121   0.113501  -4.909 2.60e-06 ***
## logmass      0.160044   0.023038   6.947 1.44e-10 ***
## Mig2W       -0.142660   0.060505  -2.358  0.01982 *  
## Nesthm      -0.008508   0.005919  -1.437  0.15297    
## xMaxFreqkHz -0.236341   0.091005  -2.597  0.01045 *  
## Hab2Open     0.133672   0.046257   2.890  0.00449 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.231 on 135 degrees of freedom
## Multiple R-squared:  0.4701, Adjusted R-squared:  0.4505 
## F-statistic: 23.95 on 5 and 135 DF,  p-value: < 2.2e-16
mt <- update(m2s, .~.-Nesthm)

amt <- anova(mt)
round(structure(100 * amt[,"Sum Sq"] / sum(amt[,"Sum Sq"]),
    names=rownames(amt)), 1)
##     logmass        Mig2 xMaxFreqkHz        Hab2   Residuals 
##        34.2         5.8         1.8         4.4        53.8
mt0 <- lm(y ~ 1)
summary(mp0) # null model for DD
## 
## Call:
## lm(formula = y ~ 1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.39617 -0.23821  0.06881  0.28168  0.96531 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.49625    0.03817   -39.2   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4532 on 140 degrees of freedom
summary(mp) # full model for DD
## 
## Call:
## lm(formula = y ~ Mig2 + xMaxFreqkHz, data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.37585 -0.18443  0.05156  0.26123  1.08980 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.6619     0.1053 -15.783  < 2e-16 ***
## Mig2W        -0.4108     0.0960  -4.280 3.48e-05 ***
## xMaxFreqkHz   0.3599     0.1479   2.432   0.0163 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.416 on 138 degrees of freedom
## Multiple R-squared:  0.1696, Adjusted R-squared:  0.1575 
## F-statistic: 14.09 on 2 and 138 DF,  p-value: 2.705e-06
## evaluating interactions
mtx <- lm(y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 +
    logmass:xMaxFreqkHz + Hab2:xMaxFreqkHz, lhreg_data)
mtx2 <- step(mtx)
## Start:  AIC=-403.35
## y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 + logmass:xMaxFreqkHz + 
##     Hab2:xMaxFreqkHz
## 
##                       Df Sum of Sq    RSS     AIC
## - logmass:xMaxFreqkHz  1  0.000128 7.2044 -405.34
## - xMaxFreqkHz:Hab2     1  0.002181 7.2064 -405.30
## <none>                             7.2042 -403.35
## - Nesthm               1  0.108346 7.3126 -403.24
## - Mig2                 1  0.290512 7.4947 -399.77
## 
## Step:  AIC=-405.34
## y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2 + xMaxFreqkHz:Hab2
## 
##                    Df Sum of Sq    RSS     AIC
## - xMaxFreqkHz:Hab2  1   0.00206 7.2064 -407.30
## <none>                          7.2044 -405.34
## - Nesthm            1   0.10919 7.3135 -405.22
## - Mig2              1   0.29587 7.5002 -401.67
## - logmass           1   2.57629 9.7806 -364.24
## 
## Step:  AIC=-407.3
## y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2
## 
##               Df Sum of Sq    RSS     AIC
## <none>                     7.2064 -407.30
## - Nesthm       1   0.11026 7.3167 -407.16
## - Mig2         1   0.29676 7.5032 -403.61
## - xMaxFreqkHz  1   0.36003 7.5664 -402.43
## - Hab2         1   0.44576 7.6522 -400.84
## - logmass      1   2.57607 9.7825 -366.21
summary(mtx2)
## 
## Call:
## lm(formula = y ~ logmass + Mig2 + Nesthm + xMaxFreqkHz + Hab2, 
##     data = lhreg_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.97677 -0.11551 -0.00027  0.15237  0.71312 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.557121   0.113501  -4.909 2.60e-06 ***
## logmass      0.160044   0.023038   6.947 1.44e-10 ***
## Mig2W       -0.142660   0.060505  -2.358  0.01982 *  
## Nesthm      -0.008508   0.005919  -1.437  0.15297    
## xMaxFreqkHz -0.236341   0.091005  -2.597  0.01045 *  
## Hab2Open     0.133672   0.046257   2.890  0.00449 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.231 on 135 degrees of freedom
## Multiple R-squared:  0.4701, Adjusted R-squared:  0.4505 
## F-statistic: 23.95 on 5 and 135 DF,  p-value: < 2.2e-16

Mixed model selection

The following models were compared, the prefix t and p indicates tau (detection distance) and phi (singing rate):

  1. M00 as null model M00,
  2. Ml0 as phylogeny-only model Mλ0,
  3. M0b as trait-only model M0β,
  4. Mlb as combined model Mλβ.
met <- "DE" # can use "SANN", "Nelder-Mead" is quickest
x <- lhreg_data
vc <- cor_matrix

## model matrix definitions
X0 <- matrix(1, nrow(x), 1) # null (for both)
colnames(X0) <- "Intercept"
Xt <- model.matrix(mt) # DD
Xp <- model.matrix(mp) # SR

## fit models for tau

tM00 <- lhreg(Y=x$logtau, X=X0, SE=x$logtauSE, V=vc, lambda=0,
    hessian=TRUE, method=met)
tMl0 <- lhreg(Y=x$logtau, X=X0, SE=x$logtauSE, V=vc, lambda=NA,
    hessian=TRUE, method=met)
tM0b <- lhreg(Y=x$logtau, X=Xt, SE=x$logtauSE, V=vc, lambda=0,
    hessian=TRUE, method=met)
tMlb <- lhreg(Y=x$logtau, X=Xt, SE=x$logtauSE, V=vc, lambda=NA,
    hessian=TRUE, method=met)

## fit models for phi

pM00 <- lhreg(Y=x$logphi, X=X0, SE=x$logphiSE, V=vc, lambda=0,
    hessian=TRUE, method=met)
pMl0 <- lhreg(Y=x$logphi, X=X0, SE=x$logphiSE, V=vc, lambda=NA,
    hessian=TRUE, method=met)
pM0b <- lhreg(Y=x$logphi, X=Xp, SE=x$logphiSE, V=vc, lambda=0,
    hessian=TRUE, method=met)
pMlb <- lhreg(Y=x$logphi, X=Xp, SE=x$logphiSE, V=vc, lambda=NA,
    hessian=TRUE, method=met)

Profile likelihood for lambda

Profile likelihood was calculated to understand how traits affect the strength of phylogeny through the variable lambda. It is possible to use lambda > 1 but it leads to extremely low likelihoods in our case.

## set up lambda values to evaluate at
lam <- seq(0, 1, by=0.01)

## parallel computation is faster
cl <- makeCluster(4)
## load package on workers
tmp <- clusterEvalQ(cl, library(lhreg))

object <- tMl0
clusterExport(cl, "object")
pl_tMl0 <- pbsapply(lam, function(z, ...) profile_lambda1(object, z, ...),
    cl=cl, method=met)

object <- tMlb
clusterExport(cl, "object")
pl_tMlb <- pbsapply(lam, function(z, ...) profile_lambda1(object, z, ...),
    cl=cl, method=met)

object <- pMl0
clusterExport(cl, "object")
pl_pMl0 <- pbsapply(lam, function(z, ...) profile_lambda1(object, z, ...),
    cl=cl, method=met)

object <- pMlb
clusterExport(cl, "object")
pl_pMlb <- pbsapply(lam, function(z, ...) profile_lambda1(object, z, ...),
    cl=cl, method=met)

stopCluster(cl) # close cluster

Leave-one-out (LOO) analysis

Leave one out cross-validation was used to see how well we could predict the values based on data from the other species, traits and phylogeny. Mean squared error (MSE) and variance components were calculated based on LOO cross validation. We also used LOO to calculate jackknife type non-parametric confidence intervals for the estimated parameters (not presented in the manuscript).

n <- nrow(x) # we will do n runs

cl <- makeCluster(4) # parallel if you wish
tmp <- clusterEvalQ(cl, library(lhreg)) # load package

loo_tM00 <- t(pbsapply(1:n, loo1, object=tM00, cl=cl))
#loo_tM00 <- t(pbsapply(1:n, loo2, object=tM00, cl=cl, method=met))
loo_tMl0 <- t(pbsapply(1:n, loo2, object=tMl0, cl=cl, method=met))
loo_tM0b <- t(pbsapply(1:n, loo1, object=tM0b, cl=cl))
#loo_tM0b <- t(pbsapply(1:n, loo2, object=tM0b, cl=cl, method=met))
loo_tMlb <- t(pbsapply(1:n, loo2, object=tMlb, cl=cl, method=met))

loo_pM00 <- t(pbsapply(1:n, loo1, object=pM00, cl=cl))
#loo_pM00 <- t(pbsapply(1:n, loo2, object=pM00, cl=cl, method=met))
loo_pMl0 <- t(pbsapply(1:n, loo2, object=pMl0, cl=cl, method=met))
loo_pM0b <- t(pbsapply(1:n, loo1, object=pM0b, cl=cl))
#loo_pM0b <- t(pbsapply(1:n, loo2, object=pM0b, cl=cl, method=met))
loo_pMlb <- t(pbsapply(1:n, loo2, object=pMlb, cl=cl, method=met))

stopCluster(cl)

Parametric bootstrap

We use the simulate method to simulate observations from a Multivariate Normal distribution according to the input object (without the observation error) to refit the model and returns simulated values and estimates.

nsim <- 999
## simulated data is nice, thus quick optimization works
metQ <- "Nelder-Mead"

cl <- makeCluster(4) # parallel if you wish
tmp <- clusterEvalQ(cl, library(lhreg)) # load package

pb_tM00 <- parametric_bootstrap(tM00, nsim=nsim, method=metQ, cl=cl)
pb_tMl0 <- parametric_bootstrap(tMl0, nsim=nsim, method=metQ, cl=cl)
pb_tM0b <- parametric_bootstrap(tM0b, nsim=nsim, method=metQ, cl=cl)
pb_tMlb <- parametric_bootstrap(tMlb, nsim=nsim, method=metQ, cl=cl)

pb_pM00 <- parametric_bootstrap(pM00, nsim=nsim, method=metQ, cl=cl)
pb_pMl0 <- parametric_bootstrap(pMl0, nsim=nsim, method=metQ, cl=cl)
pb_pM0b <- parametric_bootstrap(pM0b, nsim=nsim, method=metQ, cl=cl)
pb_pMlb <- parametric_bootstrap(pMlb, nsim=nsim, method=metQ, cl=cl)

stopCluster(cl)

Prediction intervals

We then calculate the prediction interval for an observation conditional on the other species and the known tree (this one and the other species included), and returns the bootstrap distribution of the prediction that can be used to calculate quantile based prediction intervals.

cl <- makeCluster(4)
pit <- pred_int(tM0b, pb_tM0b, cl=cl)
pip <- pred_int(pMlb, pb_pMlb, cl=cl)
stopCluster(cl)

## save the results:

save(list=c("cor_matrix", "lam", "lhreg_data", "met", "n",
    "vc", "x", "X0", "Xp", "Xt",
    "amp", "mp", "mp0", "mpx", "mpx2",
    "amt", "mt", "mt0", "mtx", "mtx2",
    "pM00", "pM0b", "pMl0", "pMlb",
    "tM00", "tM0b", "tMl0", "tMlb",
    "pl_pMl0", "pl_pMlb", "pl_tMl0", "pl_tMlb",
    "loo_pM00", "loo_pM0b", "loo_pMl0", "loo_pMlb",
    "loo_tM00", "loo_tM0b", "loo_tMl0", "loo_tMlb",
    "pb_pM00", "pb_pM0b", "pb_pMl0", "pb_pMlb",
    "pb_tM00", "pb_tM0b", "pb_tMl0", "pb_tMlb",
    "pit", "pip"),
    file="lhreg-results-DE2.rda")

Results

Load results and set some values:

library(lhreg)
#load(system.file("extdata", "lhreg-results-DE.rda", package = "lhreg"))
load(system.file("extdata", "lhreg-results-DE2.rda", package = "lhreg"))

Level <- 0.95
Crit <- -0.5*qchisq(Level, 1)
ltmp <- seq(0, 1, by=0.0001)
## red-yl-blue
Col <- c("#2C7BB6", "#6BAACF", "#ABD9E9", "#D4ECD3", "#FFFFBF", "#FED690",
    "#FDAE61", "#EA633E", "#D7191C")
Col1 <- Col[1]
Col2 <- rgb(171/255, 217/255, 233/255, 0.5) # Col[3]
Col3 <- Col[9]
Col4 <- rgb(253/255, 174/255, 97/255, 0.5) # Col[7]
prt <- exp(loo_tM0b[,1:2])
prp <- exp(loo_pMlb[,1:2])
PIt <- t(apply(exp(pit), 1, quantile, c((1-Level)/2, 1-(1-Level)/2)))
PIp <- t(apply(exp(pip), 1, quantile, c((1-Level)/2, 1-(1-Level)/2)))

library(plotrix)
size_fun <- function(x, Min=0.2, Max=1) {
    x <- x - min(x)
    x <- x / max(x)
    x <- x * (Max-Min) + Min
    x
}
col_fun <- colorRampPalette(Col) # red-yl-blue
size_col_fun <- function(x, col_fun, nbins=100, ...) {
    x <- size_fun(x, ...)
    q <- seq(min(x), max(x), by=diff(range(x))/nbins)
    i <- as.integer(cut(x, q, include.lowest = TRUE))
    col_fun(nbins)[i]
}

Table with estimates and MSE

This table has estimates, confidence intervals, MSE, ΔAIC.

get_CI <- function(x, level=0.95)
    t(apply(x$estimates, 2, quantile, c((1-level)/2, 1-(1-level)/2)))
sf <- function(z, loo, pb, type=c("wald", "jack", "boot"), level=0.95) {
    type <- match.arg(type)
    zz <- z$summary
    a <- c((1-level)/2, 1-(1-level)/2)
    dig <- 2
    if (type == "wald") {
        pcut <- function(p) {
            factor(c("***", "**", "*", "+", "ns")[as.integer(cut(p,
                c(1, 0.1, 0.05, 0.01, 0.001, 0),
                include.lowest=TRUE, right=FALSE))],
                levels=c("***", "**", "*", "+", "ns"))
        }
        out <- structure(sapply(1:nrow(zz), function(i)
            paste0(round(zz[i,1], dig), " (SE +/- ", round(zz[i,2], dig),
            pcut(zz[i,4]), ")")), names=rownames(zz))
    }
    if (type == "jack") {
        CI <- t(apply(rbind(zz[,1], loo[,3:ncol(loo),drop=FALSE]), 2,
            quantile, a))
        out <- structure(sapply(1:nrow(zz), function(i)
            paste0(round(zz[i,1], dig), " (", round(CI[i,1], dig), ", ",
            round(CI[i,2], dig), ")")), names=rownames(zz))
    }
    if (type == "boot") {
        CI <- get_CI(pb, level)
        out <- structure(sapply(1:nrow(zz), function(i)
            paste0(round(zz[i,1], dig), " (", round(CI[i,1], dig), ", ",
            round(CI[i,2], dig), ")")), names=rownames(zz))
    }
    out
}
## AIC tables
aict <- AIC(tM00, tMl0, tM0b, tMlb)
aict$dAIC <- aict$AIC-min(aict$AIC)

aicp <- AIC(pM00, pMl0, pM0b, pMlb)
aicp$dAIC <- aicp$AIC-min(aicp$AIC)

cbind(aict, t(sapply(list(tM00, tMl0, tM0b, tMlb),
    function(z) z$summary[c("sigma","lambda"), 1])))
##      df       AIC     dAIC     sigma       lambda
## tM00  2 72.170443 80.68514 0.3044325 0.000000e+00
## tMl0  3 45.629510 54.14420 0.4122631 7.590267e-01
## tM0b  6 -8.514694  0.00000 0.2203313 0.000000e+00
## tMlb  7 -6.511444  2.00325 0.2203338 4.539993e-05
cbind(aicp, t(sapply(list(pM00, pMl0, pM0b, pMlb),
    function(z) z$summary[c("sigma","lambda"), 1])))
##      df      AIC      dAIC     sigma    lambda
## pM00  2 151.5213 41.061422 0.3726461 0.0000000
## pMl0  3 112.1999  1.740013 0.5319832 0.8352825
## pM0b  4 123.4773 13.017366 0.3275378 0.0000000
## pMlb  5 110.4599  0.000000 0.4885140 0.7887666
## MSE
SSEt <- c(
    tM00 = sum((loo_tM00[,"pred"] - tM00$Y)^2),
    tMl0 = sum((loo_tMl0[,"pred"] - tMl0$Y)^2),
    tM0b = sum((loo_tM0b[,"pred"] - tM0b$Y)^2),
    tMlb = sum((loo_tMlb[,"pred"] - tMlb$Y)^2))
SSEp <- c(
    pM00 = sum((loo_pM00[,"pred"] - pM00$Y)^2),
    pMl0 = sum((loo_pMl0[,"pred"] - pMl0$Y)^2),
    pM0b = sum((loo_pM0b[,"pred"] - pM0b$Y)^2),
    pMlb = sum((loo_pMlb[,"pred"] - pMlb$Y)^2))
MSEt <- SSEt / n
MSEp <- SSEp / n

Type <- "boot" # can be wald, jack, boot
zzz <- list(
    M00=sf(pM00, loo_pM00, pb_pM00, Type, Level),
    Ml0=sf(pMl0, loo_pMl0, pb_pMl0, Type, Level),
    M0b=sf(pM0b, loo_pM0b, pb_pM0b, Type, Level),
    Mlb=sf(pMlb, loo_pMlb, pb_pMlb, Type, Level))
m <- matrix("", length(zzz[[4]]), 4)
rownames(m) <- names(zzz[[4]])
colnames(m) <- c("M00", "Ml0", "M0b", "Mlb")
for (i in 1:4) {
    j <- match(names(zzz[[i]]), rownames(m))
    m[j,i] <- zzz[[i]]
}
m["lambda", c("M00", "M0b")] <- "0 (fixed)"
#m[m==""] <- "n/a"
m1 <- m

zzz <- list(
    M00=sf(tM00, loo_tM00, pb_tM00, Type, Level),
    Ml0=sf(tMl0, loo_tMl0, pb_tMl0, Type, Level),
    M0b=sf(tM0b, loo_tM0b, pb_tM0b, Type, Level),
    Mlb=sf(tMlb, loo_tMlb, pb_tMlb, Type, Level))
m <- matrix("", length(zzz[[4]]), 4)
rownames(m) <- names(zzz[[4]])
colnames(m) <- c("M00", "Ml0", "M0b", "Mlb")
for (i in 1:4) {
    j <- match(names(zzz[[i]]), rownames(m))
    m[j,i] <- zzz[[i]]
}
m["lambda", c("M00", "M0b")] <- "0 (fixed)"
#m[m==""] <- "n/a"
m2 <- m

m1 <- rbind(m1, df=aicp$df, dAIC=round(aicp$dAIC, 3),
    XV_MSE=round(MSEp, 3))
m2 <- rbind(m2, df=aict$df, dAIC=round(aict$dAIC, 3),
    XV_MSE=round(MSEt, 3))

print.default(m1, quote=FALSE) # SR results
##                  M00                  Ml0                  M0b                 
## beta_Intercept   -1.45 (-1.51, -1.39) -1.71 (-2.15, -1.24) -1.63 (-1.79, -1.47)
## beta_Mig2W                                                 -0.37 (-0.52, -0.23)
## beta_xMaxFreqkHz                                           0.37 (0.14, 0.61)   
## sigma            0.37 (0.33, 0.41)    0.53 (0.39, 0.64)    0.33 (0.29, 0.36)   
## lambda           0 (fixed)            0.84 (0.58, 0.93)    0 (fixed)           
## df               2                    3                    4                   
## dAIC             41.061               1.74                 13.017              
## XV_MSE           0.207                0.154                0.178               
##                  Mlb                 
## beta_Intercept   -1.72 (-2.13, -1.33)
## beta_Mig2W       -0.2 (-0.39, -0.01) 
## beta_xMaxFreqkHz 0.19 (-0.06, 0.43)  
## sigma            0.49 (0.34, 0.59)   
## lambda           0.79 (0.47, 0.9)    
## df               5                   
## dAIC             0                   
## XV_MSE           0.153
print.default(m2, quote=FALSE) # DD results
##                  M00                 Ml0                 M0b                 
## beta_Intercept   -0.2 (-0.24, -0.15) -0.08 (-0.42, 0.26) -0.58 (-0.77, -0.39)
## beta_logmass                                             0.16 (0.12, 0.2)    
## beta_Mig2W                                               -0.17 (-0.29, -0.06)
## beta_xMaxFreqkHz                                         -0.23 (-0.39, -0.06)
## beta_Hab2Open                                            0.14 (0.07, 0.22)   
## sigma            0.3 (0.27, 0.34)    0.41 (0.31, 0.5)    0.22 (0.19, 0.24)   
## lambda           0 (fixed)           0.76 (0.44, 0.89)   0 (fixed)           
## df               2                   3                   6                   
## dAIC             80.685              54.144              0                   
## XV_MSE           0.098               0.077               0.057               
##                  Mlb                 
## beta_Intercept   -0.58 (-0.78, -0.38)
## beta_logmass     0.16 (0.11, 0.2)    
## beta_Mig2W       -0.17 (-0.28, -0.05)
## beta_xMaxFreqkHz -0.23 (-0.4, -0.06) 
## beta_Hab2Open    0.14 (0.06, 0.23)   
## sigma            0.22 (0.19, 0.24)   
## lambda           0 (0, 0)            
## df               7                   
## dAIC             2.003               
## XV_MSE           0.054

Shared variation is calculated as:

Var_fun <- function(MSE) {
    Var <- 100*(MSE[1]-MSE[-1])/MSE[1]
    Var <- c(Var, Var[1]+Var[2]-Var[3])
    names(Var) <- c("phylo", "traits", "both", "shared")
    Var
}
## SR
round(Var_fun(MSEp), 1)
##  phylo traits   both shared 
##   25.8   14.2   25.8   14.2
## DD
round(Var_fun(MSEt), 1)
##  phylo traits   both shared 
##   21.5   42.2   44.9   18.8

Tree with SR, DD, and trait values

Load the 1000 posterior trees, pick one and plot trait values alongside the tree.

library(ape)
load(system.file("extdata", "mph.rda", package = "lhreg"))
tre <- mph[[1000]] # pick one tree

ii <- match(tre$tip.label, rownames(lhreg_data))
d2 <- lhreg_data[ii,]
NAMES <- paste0(d2$common_name, " (", d2$spp, ")")
tre$tip.label <- NAMES
xy <- data.frame(
    x=node.depth.edgelength(tre)[1:length(tre$tip.label)],
    y=node.height(tre)[1:length(tre$tip.label)])
phy_pts_size <- function(z, vari, ...)
    points(xy[,1] + z, xy[,2], pch=19, cex=size_fun(vari, Min=0.3, Max=1.2), ...)
phy_pts_col <- function(z, vari, col=1, ...)
    points(xy[,1] + z, xy[,2], pch=19,
        cex=size_fun(vari, Min=0.3, Max=1.2),
        col=size_col_fun(vari, colorRampPalette(c("#000000", col)), Min=0.3), ...)
phy_pts_2 <- function(z, vari, cex=0.6, col="#000000", ...) {
    points(xy[,1] + z, xy[,2], pch=19,
        col=c(col, "#FFFFFF")[as.integer(vari)], cex=cex, ...)
    points(xy[,1] + z, xy[,2], pch=21, col=col, cex=cex)
}

#pdf("Fig1.pdf", width=10, height=15)
op <- par(mar=c(1,1,1,1))

plot(tre, cex=0.6, label.offset=22, font=1)
segments(xy[,1], xy[,2], xy[,1]+21, xy[,2], lwd=1, col=1)
phy_pts_size(2, exp(d2$logphi), col=Col1)
phy_pts_size(5, exp(d2$logtau), col=Col3)
phy_pts_2(10, d2$Mig2, col=1)
phy_pts_size(13, d2$MaxFreqkHz, col="#4daf4a")
phy_pts_size(16, sqrt(exp(d2$logmass)), col="#984ea3")
phy_pts_2(19, d2$Hab2, col="#ff7f00")
text(xy[1,1]+c(2,5,10,13,16,19), rep(142, 6),
    c("SR", "DD", "Migr", "Pitch", "Mass", "Habitat"),
    pos=4, srt=90, cex=0.65, offset=0)

par(op)
#dev.off()

Profile likelihood profiles for lambda

#pdf("FigPL.pdf", width=14, height=6)
op <- par(mfrow=c(1,2))

Res1 <- pl_pMl0
Res2 <- pl_pMlb
yv <- exp(Res1-max(Res1))
plot(lam, yv, type="n", lwd=1, ylim=exp(c(2*Crit, 0)),
    xlab=expression(lambda), ylab="Profile Likelihood Ratio")
tmp1 <- splinefun(lam, yv)(ltmp)
i1 <- tmp1 > exp(Crit)
yv <- exp(Res2-max(Res2))
tmp2 <- splinefun(lam, yv)(ltmp)
i2 <- tmp2 > exp(Crit)
polygon(c(ltmp[i1], rev(ltmp[i1])),
    c(tmp1[i1], rep(-1, sum(i1))),
    col=Col2, border=NA)
polygon(c(ltmp[i2], rev(ltmp[i2])),
    c(tmp2[i2], rep(-1, sum(i2))),
    col=Col4, border=NA)
abline(h=exp(Crit), col="grey")
lines(ltmp, tmp1, col=Col1, lwd=1)
lines(ltmp[i1], tmp1[i1], col=Col1, lwd=3)
lines(rep(ltmp[which.max(tmp1)], 2), c(1, -1), col=Col1)
lines(ltmp, tmp2, col=Col3, lwd=1)
lines(ltmp[i2], tmp2[i2], col=Col3, lwd=3)
lines(rep(ltmp[which.max(tmp2)], 2), c(1, -1), col=Col3)
box()
legend(0.1, 1, bty="n", border=c(Col1, Col3), fill=c(Col2, Col4), pt.cex=2, pt.lwd=2,
    legend=c(expression(M[lambda*0]-SR), expression(M[lambda*beta]-SR)))
round(c(Max_Ml0=ltmp[which.max(tmp1)], CI=range(ltmp[i1])), 3)
## Max_Ml0     CI1     CI2 
##   0.835   0.627   0.933
round(c(Max_Mlx=ltmp[which.max(tmp2)], CI=range(ltmp[i2])), 3)
## Max_Mlx     CI1     CI2 
##   0.789   0.447   0.921
Res1 <- pl_tMl0
Res2 <- pl_tMlb
yv <- exp(Res1-max(Res1))
plot(lam, yv, type="n", lwd=1, ylim=exp(c(2*Crit, 0)),
    xlab=expression(lambda), ylab="Profile Likelihood Ratio")
tmp1 <- splinefun(lam, yv)(ltmp)
i1 <- tmp1 > exp(Crit)
yv <- exp(Res2-max(Res2))
tmp2 <- splinefun(lam, yv)(ltmp)
i2 <- tmp2 > exp(Crit)
polygon(c(ltmp[i1], rev(ltmp[i1])),
    c(tmp1[i1], rep(-1, sum(i1))),
    col=Col2, border=NA)
polygon(c(ltmp[i2], rev(ltmp[i2])),
    c(tmp2[i2], rep(-1, sum(i2))),
    col=Col4, border=NA)
abline(h=exp(Crit), col="grey")
lines(ltmp, tmp1, col=Col1, lwd=1)
lines(ltmp[i1], tmp1[i1], col=Col1, lwd=3)
lines(rep(ltmp[which.max(tmp1)], 2), c(1, -1), col=Col1)
lines(ltmp, tmp2, col=Col3, lwd=1)
lines(ltmp[i2], tmp2[i2], col=Col3, lwd=3)
lines(rep(ltmp[which.max(tmp2)], 2), c(1, -1), col=Col3)
box()
legend(0.1, 1, bty="n", border=c(Col1, Col3), fill=c(Col2, Col4), pt.cex=2, pt.lwd=2,
    legend=c(expression(M[lambda*0]-DD), expression(M[lambda*beta]-DD)))

round(c(Max_Ml0=ltmp[which.max(tmp1)], CI=range(ltmp[i1])), 3)
## Max_Ml0     CI1     CI2 
##   0.759   0.504   0.899
round(c(Max_Mlx=ltmp[which.max(tmp2)], CI=range(ltmp[i2])), 3)
## Max_Mlx     CI1     CI2 
##   0.000   0.000   0.421
par(op)
#dev.off()

Bootstrap distributions of lambda

#pdf("FigPB.pdf", width=10, height=10)
op <- par(mfrow=c(2,2))
plot(density(pb_pMl0$estimates[,"lambda"]),
    xlim=c(0,1), main="SR Ml0", col=Col1)
plot(density(pb_pMlb$estimates[,"lambda"]),
    xlim=c(0,1), main="SR Mlb", col=Col1)
plot(density(pb_tMl0$estimates[,"lambda"]),
    xlim=c(0,1), main="DD Ml0", col=Col3)
plot(density(pb_tMlb$estimates[,"lambda"]),
    xlim=c(0,1), main="DD Mlb", col=Col3)

par(op)
#dev.off()

LOO cross validation plots

#pdf("Fig2.pdf", width=12.75, height=7)
op <- par(mfrow=c(1,2))

Max <- 0.7
D <- as.matrix(dist(prp))
diag(D) <- Inf
D <- apply(D, 1, min)
plot(prp, xaxs = "i", yaxs = "i", type="n", asp=1,
    ylim=c(0, Max), xlim=c(0, Max),
    xlab="Time-removal SR Estimate (/min)",
    ylab="LOO SR Estimate (/min)")
abline(0,2,lty=2, col="grey")
abline(0,1/2,lty=2, col="grey")
abline(0,1.5,lty=2, col="grey")
abline(0,1/1.5,lty=2, col="grey")
abline(0,1,lty=1, col=1)
r0 <- size_fun(x$MaxFreqkHz, 0.2*Max/50, Max/50)
draw.ellipse(prp[,1], prp[,2], r0, r0,
    border=c(Col1,Col3)[as.integer(x$Mig2)])
segments(prp[,1], PIp[,1], prp[,1], PIp[,2],
    col=c(Col1,Col3)[as.integer(x$Mig2)], lwd=1)
box()
legend("topleft", pch=21, col=c(Col1,Col3),
    pt.cex=c(2,2), bty="n",
    legend=c("Migrant", "Resident"))
r <- seq(0.2*Max/50, Max/50, len=5)
draw.ellipse(rep(0.06, 5), 0.55+r-max(r), r, r, border=1)
text(c(0.09, 0.06, 0.06), c(0.61, 0.52, 0.58),
    c("Song Pitch (kHz)",round(range(x$MaxFreqkHz),1)),
    cex=c(1,0.75,0.75))
text(0.9*Max, 0.05*Max, expression(M[lambda*beta]-SR))
#Ti <- D > 0.03
#Ti <- D > 0.03 | (prp[,1]/prp[,2] > 2 | prp[,1]/prp[,2] < 1/2)
Ti <- D > 0.03 | (prp[,1]/prp[,2] > 3.2 | prp[,1]/prp[,2] < 1/3.2)
text(prp[,1], prp[,2], ifelse(Ti, as.character(x$spp), NA),
    cex=0.6, pos=3, col=1)

Max <- 100*2.1
D <- as.matrix(dist(prt))
diag(D) <- Inf
D <- apply(D, 1, min)
plot(100*prt, xaxs = "i", yaxs = "i", type="n", asp=1,
    ylim=c(0, Max), xlim=c(0, Max),
    xlab="Distance-sampling DD Estimate (m)",
    ylab="LOO DD Estimate (m)")
abline(0,2,lty=2, col="grey")
abline(0,1/2,lty=2, col="grey")
abline(0,1.5,lty=2, col="grey")
abline(0,1/1.5,lty=2, col="grey")
abline(0,1,lty=1, col=1)
r0 <- size_fun(x$logmass, 0.2*Max/50, Max/50)
draw.ellipse(100*prt[,1], 100*prt[,2], r0, r0,
    border=c(Col1,Col3)[as.integer(x$Hab2)])
segments(100*prt[,1], 100*PIt[,1], 100*prt[,1], 100*PIt[,2],
    col=c(Col1,Col3)[as.integer(x$Hab2)], lwd=1)
box()
legend("topleft", pch=21, col=c(Col1,Col3), pt.cex=c(2,2), bty="n",
    legend=c("Habitat: Closed", "Habitat: Open"))
r <- seq(0.2*Max/50, Max/50, len=5)
S <- Max/0.7
draw.ellipse(S*rep(0.06, 5), S*0.55+r-max(r), r, r, border=1)
text(S*c(0.09, 0.06, 0.06), S*c(0.61, 0.52, 0.58),
    c("Body Mass (g)",round(range(x$logmass),1)),
    cex=c(1,0.75,0.75))
text(0.9*Max, 0.05*Max, expression(M[0*beta]-DD))
Ti <- D > 0.09 | (prt[,1]/prt[,2] > 2 | prt[,1]/prt[,2] < 1/2)
text(100*prt[,1], 100*prt[,2], ifelse(Ti, as.character(x$spp), NA),
    cex=0.6, pos=3, col=1)

par(op)
#dev.off()

The percent of species where prediction intervals overlapped the estimated values:

library(intrval)
## SR
## # species with overlapping PI
sum(prp[,"obs"] %[]% PIp)
## [1] 25
## # species with >150% or <66% of original estimates
sum((prp[,"pred"]/prp[,"obs"]) %)(% c(3/2, 2/3))
## [1] 34
## # species with >200% or <50% of original estimates
sum((prp[,"pred"]/prp[,"obs"]) %)(% c(2, 1/2))
## [1] 12
## DD
## % species with overlapping PI
sum(prt[,"obs"] %[]% PIt)
## [1] 45
## # species with >150% or <66% of original estimates
sum((prt[,"pred"]/prt[,"obs"]) %)(% c(3/2, 2/3))
## [1] 7
## # species with >200% or <50% of original estimates
sum((prt[,"pred"]/prt[,"obs"]) %)(% c(2, 1/2))
## [1] 3

Mapping continuous traits on the tree

We need to hack the phytools::contMap function to produce non-rainbow colors. Then we produce trees for the continuous traits.

library(phytools)
## Loading required package: maps
## 
## Attaching package: 'phytools'
## The following object is masked from 'package:plotrix':
## 
##     rescale
contMap2 <-
function (tree, x, res = 100, fsize = NULL, ftype = NULL, lwd = 4,
    legend = NULL, lims = NULL, outline = TRUE, sig = 3, type = "phylogram",
    direction = "rightwards", plot = TRUE, col_fun=rainbow, ...)
{
    if (!inherits(tree, "phylo"))
        stop("tree should be an object of class \"phylo\".")
    if (hasArg(mar))
        mar <- list(...)$mar
    else mar <- rep(0.3, 4)
    if (hasArg(offset))
        offset <- list(...)$offset
    else offset <- NULL
    if (hasArg(method))
        method <- list(...)$method
    else method <- "fastAnc"
    if (hasArg(hold))
        hold <- list(...)$hold
    else hold <- TRUE
    if (hasArg(leg.txt))
        leg.txt <- list(...)$leg.txt
    else leg.txt <- "trait value"
    h <- max(nodeHeights(tree))
    steps <- 0:res/res * max(h)
    H <- nodeHeights(tree)
    if (method == "fastAnc")
        a <- fastAnc(tree, x)
    else if (method == "anc.ML") {
        fit <- anc.ML(tree, x)
        a <- fit$ace
        if (!is.null(fit$missing.x))
            x <- c(x, fit$missing.x)
    }
    else if (method == "user") {
        if (hasArg(anc.states))
            anc.states <- list(...)$anc.states
        else {
            cat("No ancestral states have been provided. Using states estimated with fastAnc.\n\n")
            a <- fastAnc(tree, x)
        }
        if (length(anc.states) < tree$Nnode) {
            nodes <- as.numeric(names(anc.states))
            tt <- tree
            for (i in 1:length(nodes)) {
                M <- matchNodes(tt, tree, method = "distances")
                ii <- M[which(M[, 2] == nodes[i]), 1]
                tt <- bind.tip(tt, nodes[i], edge.length = 0,
                  where = ii)
            }
            a <- fastAnc(tt, c(x, anc.states))
            M <- matchNodes(tree, tt, method = "distances")
            a <- a[as.character(M[, 2])]
            names(a) <- M[, 1]
        }
        else {
            if (is.null(names(anc.states)))
                names(anc.states) <- 1:tree$Nnode + Ntip(tree)
            a <- anc.states[as.character(1:tree$Nnode + Ntip(tree))]
        }
    }
    y <- c(a, x[tree$tip.label])
    names(y)[1:Ntip(tree) + tree$Nnode] <- 1:Ntip(tree)
    A <- matrix(y[as.character(tree$edge)], nrow(tree$edge),
        ncol(tree$edge))
    cols <- col_fun(1001)
    names(cols) <- 0:1000
    if (is.null(lims))
        lims <- c(min(y), max(y))
    trans <- 0:1000/1000 * (lims[2] - lims[1]) + lims[1]
    names(trans) <- 0:1000
    tree$maps <- vector(mode = "list", length = nrow(tree$edge))
    for (i in 1:nrow(tree$edge)) {
        XX <- cbind(c(H[i, 1], steps[intersect(which(steps >
            H[i, 1]), which(steps < H[i, 2]))]), c(steps[intersect(which(steps >
            H[i, 1]), which(steps < H[i, 2]))], H[i, 2])) - H[i,
            1]
        YY <- rowMeans(XX)
        if (!all(YY == 0)) {
            b <- vector()
            for (j in 1:length(YY)) b[j] <- (A[i, 1]/YY[j] +
                A[i, 2]/(max(XX) - YY[j]))/(1/YY[j] + 1/(max(XX) -
                YY[j]))
        }
        else b <- A[i, 1]
        d <- sapply(b, phytools:::getState, trans = trans)
        tree$maps[[i]] <- XX[, 2] - XX[, 1]
        names(tree$maps[[i]]) <- d
    }
    tree$mapped.edge <- phytools:::makeMappedEdge(tree$edge, tree$maps)
    tree$mapped.edge <- tree$mapped.edge[, order(as.numeric(colnames(tree$mapped.edge)))]
    class(tree) <- c("simmap", setdiff(class(tree), "simmap"))
    xx <- list(tree = tree, cols = cols, lims = lims)
    class(xx) <- "contMap"
    if (plot)
        phytools:::plot.contMap(xx, fsize = fsize, ftype = ftype, lwd = lwd,
            legend = legend, outline = outline, sig = sig, type = type,
            mar = mar, direction = direction, offset = offset,
            hold = hold, leg.txt = leg.txt)
    invisible(xx)
}

## log singing rates
contMap2(tre, structure(d2$logphi, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)

## log detection distances
contMap2(tre, structure(d2$logtau, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)

## log body mass
contMap2(tre, structure(d2$logmass, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)

## pitch
contMap2(tre, structure(d2$MaxFreqkHz, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)

## migratory status
contMap2(tre, structure(d2$Mig2, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)

## habitat associations
contMap2(tre, structure(d2$Hab2, .Names=NAMES),
    fsize=0.5, outline=FALSE, col_fun=col_fun)