# Analysis of Redstart data illustrating basic RMark features
# Reproduce Figure 2 where the Nest survival is computed for each year.

# 2019-05-01 CJS Initial code

# Sherry TW, Wilson S, Hunter S, Holmes RT (2015) 
# Impacts of nest predators and weather on reproductive success and 
# population limitation in a long-distance migratory songbird. 
# Journal of Avian Biology 46(6): 559-569. https://doi.org/10.1111/jav.00536

# Data from
# Sherry TW, Wilson S, Hunter S, Holmes RT (2015) 
# Data from: Impacts of nest predators and weather on reproductive success and 
# population limitation in a long-distance migratory songbird. 
# Dryad Digital Repository. https://doi.org/10.5061/dryad.73870


library(ggplot2)
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
library(readxl)
library(RMark)
## This is RMark 2.2.6
##  Documentation available at http://www.phidot.org/software/mark/rmark/RMarkDocumentation.zip
# The dataframe must contain the following fields with the following names
#
#    FirstFound: day the nest was first found
#    LastPresent: last day that a chick was present in the nest
#    LastChecked: last day the nest was checked
#    Fate: fate of the nest; 0=hatch an
#    Freq: number of nests with this data
#
# In this example, the multiple visits to a nest have been collapsed
# to a single record for each nest.
# In more complex examples, you may have multple records per nest
# as shown in the mallard example.
#

reddata <- readxl::read_excel(file.path("..","Sherry.xlsx"), 
                               sheet="NestData")
head(reddata)
## # A tibble: 6 x 11
##   NestId FirstFound LastPresent LastChecked  Fate  Freq Height BaffleStatus
##   <chr>       <dbl>       <dbl>       <dbl> <dbl> <dbl>  <dbl> <chr>       
## 1 /*198~         11          11          18     1     1   16.9 N           
## 2 /*198~         13          22          23     1     1   10.5 N           
## 3 /*198~          7          26          26     0     1    4.8 N           
## 4 /*198~         12          14          20     1     1    3.7 N           
## 5 /*198~          6          20          25     1     1   10.7 N           
## 6 /*198~         11          19          20     1     1   17.8 N           
## # ... with 3 more variables: DBH <dbl>, AgeDay1 <dbl>, Year <chr>
reddata <- as.data.frame(reddata)


# get the yearly date and merge with the nest data
annual.data <- readxl::read_excel(file.path("..","Sherry.xlsx"),
                                  sheet="AnnualCovariates", skip=9)
head(annual.data)
## # A tibble: 6 x 7
##    Year Density Predators MayTemp JuneTemp MayRain JuneRain
##   <dbl>   <dbl>     <dbl>   <dbl>    <dbl>   <dbl>    <dbl>
## 1  1983   0.867       2.4    8.89     17.1   194.      35.3
## 2  1984   0.467       0.5    9.06     16.2   312.     180. 
## 3  1985   0.589       3.4   10.6      13.2   107.     130  
## 4  1986   0.439       6     12.2      13.4   128.      89.6
## 5  1987   0.372       1.7   10.9      15.4    91.6    200. 
## 6  1988   0.361       0.3   12        14.4    97.8     70.2
dim(reddata)
## [1] 537  11
reddata <- merge(reddata, annual.data, all.x=TRUE)
dim(reddata)
## [1] 537  17
# any missing data?
sum(!complete.cases(reddata))
## [1] 0
# as noted in the paper, we remove nests with baffeling
dim(reddata)
## [1] 537  17
reddata <- reddata[ !(reddata$BaffleStatus=="Y"),]
dim(reddata)
## [1] 466  17
# create factor variable for year
reddata$YearF <- factor(reddata$Year)

# what are the parameters of the model
# There is only one parameter, the daily survival probality (S)
setup.parameters("Nest", check=TRUE)
## [1] "S"
# Now we look through each year of the study to compute the DSR using a S(.) model
# and compute the nest survival probability
fits <- plyr::dlply(reddata, c("Year","MayTemp"), function(x){
   cat("Fitting ", x$Year[1], x$MayTemp[1], "\n")
  
   # 1. Process the data.
   # The nocc variable is the data at which hatching occurs
   red.proc <- process.data(x, model="Nest", group=c("YearF"), nocc=max(x$LastChecked))
   red.proc


   # 2. Examine and/or modify the ddl. (Not done here)
   red.ddl <- make.design.data(red.proc)
   str(red.ddl)
   red.ddl 
 
   # 3. Fit the dot model 
   fit <- RMark::mark(red.proc, ddl=red.ddl,
                     model="Nest",
                     model.parameters=list(
                       S   =list(formula=~1))
                     )
   print(summary(fit))
   
   # 4. Estimate the nest success for 20 days
   dsr <-  get.real(fit, "S", se=TRUE, vcv=TRUE, expand=TRUE)

   ns    <- prod(dsr$estimates$estimate[1:20])
   ns.se <- deltamethod.special("prod", 
                                dsr$estimates$estimate[1:20],
                                dsr$vcv.real[1:20, 1:20])
   list(red.proc=red.proc, red.ddl=red.ddl, fit=fit, dsr=dsr, ns=ns, ns.se=ns.se)
  
})
## Fitting  1983 8.89 
## List of 2
##  $ S       :'data.frame':    55 obs. of  8 variables:
##   ..$ par.index  : int [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1983": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 55 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 55 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  133.5122
## AICc :  135.525
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.570125 0.2124018 2.153818 2.986433
## 
## 
## Real Parameter S
##         1        2        3        4        5        6        7        8
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##         9       10       11       12       13       14       15       16
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        17       18       19       20       21       22       23       24
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        25       26       27       28       29       30       31       32
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        33       34       35       36       37       38       39       40
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        41       42       43       44       45       46       47       48
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        49       50       51       52       53       54       55
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  133.5122
## AICc :  135.525
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.570125 0.2124018 2.153818 2.986433
## 
## 
## Real Parameter S
##         1        2        3        4        5        6        7        8
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##         9       10       11       12       13       14       15       16
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        17       18       19       20       21       22       23       24
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        25       26       27       28       29       30       31       32
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        33       34       35       36       37       38       39       40
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        41       42       43       44       45       46       47       48
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
##        49       50       51       52       53       54       55
##  0.928914 0.928914 0.928914 0.928914 0.928914 0.928914 0.928914
## Fitting  1984 9.06 
## List of 2
##  $ S       :'data.frame':    53 obs. of  8 variables:
##   ..$ par.index  : int [1:53] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:53] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1984": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 53 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 53 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:53] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:53] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  128.8802
## AICc :  130.8888
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.292025 0.2470683 2.807771 3.776279
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##          8         9        10        11        12        13        14
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         15        16        17        18        19        20        21
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         22        23        24        25        26        27        28
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         29        30        31        32        33        34        35
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         36        37        38        39        40        41        42
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         43        44        45        46        47        48        49
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         50        51        52        53
##  0.9641542 0.9641542 0.9641542 0.9641542
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  128.8802
## AICc :  130.8888
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.292025 0.2470683 2.807771 3.776279
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##          8         9        10        11        12        13        14
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         15        16        17        18        19        20        21
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         22        23        24        25        26        27        28
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         29        30        31        32        33        34        35
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         36        37        38        39        40        41        42
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         43        44        45        46        47        48        49
##  0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542 0.9641542
##         50        51        52        53
##  0.9641542 0.9641542 0.9641542 0.9641542
## Fitting  1985 10.6 
## List of 2
##  $ S       :'data.frame':    55 obs. of  8 variables:
##   ..$ par.index  : int [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1985": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 55 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 55 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  80.16544
## AICc :  82.18065
## 
## Beta
##               estimate        se     lcl      ucl
## S:(Intercept) 3.089103 0.2954554 2.51001 3.668196
## 
## 
## Real Parameter S
##         1        2        3        4        5        6        7        8
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##         9       10       11       12       13       14       15       16
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        17       18       19       20       21       22       23       24
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        25       26       27       28       29       30       31       32
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        33       34       35       36       37       38       39       40
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        41       42       43       44       45       46       47       48
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        49       50       51       52       53       54       55
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  80.16544
## AICc :  82.18065
## 
## Beta
##               estimate        se     lcl      ucl
## S:(Intercept) 3.089103 0.2954554 2.51001 3.668196
## 
## 
## Real Parameter S
##         1        2        3        4        5        6        7        8
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##         9       10       11       12       13       14       15       16
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        17       18       19       20       21       22       23       24
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        25       26       27       28       29       30       31       32
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        33       34       35       36       37       38       39       40
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        41       42       43       44       45       46       47       48
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
##        49       50       51       52       53       54       55
##  0.956441 0.956441 0.956441 0.956441 0.956441 0.956441 0.956441
## Fitting  1986 12.16 
## List of 2
##  $ S       :'data.frame':    50 obs. of  8 variables:
##   ..$ par.index  : int [1:50] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:50] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1986": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 50 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 50 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:50] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:50] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 4 4 4 4 4 4 4 4 4 4 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  93.88375
## AICc :  95.89121
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.881376 0.3046328 3.284295 4.478456
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##          8         9        10        11        12        13        14
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         15        16        17        18        19        20        21
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         22        23        24        25        26        27        28
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         29        30        31        32        33        34        35
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         36        37        38        39        40        41        42
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         43        44        45        46        47        48        49
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         50
##  0.9797943
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  93.88375
## AICc :  95.89121
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.881376 0.3046328 3.284295 4.478456
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##          8         9        10        11        12        13        14
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         15        16        17        18        19        20        21
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         22        23        24        25        26        27        28
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         29        30        31        32        33        34        35
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         36        37        38        39        40        41        42
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         43        44        45        46        47        48        49
##  0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943 0.9797943
##         50
##  0.9797943
## Fitting  1987 10.92 
## List of 2
##  $ S       :'data.frame':    38 obs. of  8 variables:
##   ..$ par.index  : int [1:38] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:38] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1987": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 38 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 38 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:38] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:38] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 5 5 5 5 5 5 5 5 5 5 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  75.14853
## AICc :  77.15906
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept)  3.73995 0.3373295 3.078784 4.401116
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##          8         9        10        11        12        13        14
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         15        16        17        18        19        20        21
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         22        23        24        25        26        27        28
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         29        30        31        32        33        34        35
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         36        37        38
##  0.9767959 0.9767959 0.9767959
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  75.14853
## AICc :  77.15906
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept)  3.73995 0.3373295 3.078784 4.401116
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##          8         9        10        11        12        13        14
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         15        16        17        18        19        20        21
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         22        23        24        25        26        27        28
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         29        30        31        32        33        34        35
##  0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959 0.9767959
##         36        37        38
##  0.9767959 0.9767959 0.9767959
## Fitting  1988 12 
## List of 2
##  $ S       :'data.frame':    53 obs. of  8 variables:
##   ..$ par.index  : int [1:53] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:53] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1988": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 53 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 53 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:53] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:53] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 6 6 6 6 6 6 6 6 6 6 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  48.32463
## AICc :  50.33463
## 
## Beta
##               estimate        se     lcl      ucl
## S:(Intercept) 4.380721 0.4500158 3.49869 5.262752
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##          8         9        10        11        12        13        14
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         15        16        17        18        19        20        21
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         22        23        24        25        26        27        28
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         29        30        31        32        33        34        35
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         36        37        38        39        40        41        42
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         43        44        45        46        47        48        49
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         50        51        52        53
##  0.9876384 0.9876384 0.9876384 0.9876384
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  48.32463
## AICc :  50.33463
## 
## Beta
##               estimate        se     lcl      ucl
## S:(Intercept) 4.380721 0.4500158 3.49869 5.262752
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##          8         9        10        11        12        13        14
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         15        16        17        18        19        20        21
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         22        23        24        25        26        27        28
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         29        30        31        32        33        34        35
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         36        37        38        39        40        41        42
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         43        44        45        46        47        48        49
##  0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384 0.9876384
##         50        51        52        53
##  0.9876384 0.9876384 0.9876384 0.9876384
## Fitting  1989 11.89 
## List of 2
##  $ S       :'data.frame':    50 obs. of  8 variables:
##   ..$ par.index  : int [1:50] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:50] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1989": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 50 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 50 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:50] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:50] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 7 7 7 7 7 7 7 7 7 7 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  88.57516
## AICc :  90.58755
## 
## Beta
##               estimate       se      lcl     ucl
## S:(Intercept) 3.360827 0.306726 2.759644 3.96201
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##          8         9        10        11        12        13        14
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         15        16        17        18        19        20        21
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         22        23        24        25        26        27        28
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         29        30        31        32        33        34        35
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         36        37        38        39        40        41        42
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         43        44        45        46        47        48        49
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         50
##  0.9664576
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  88.57516
## AICc :  90.58755
## 
## Beta
##               estimate       se      lcl     ucl
## S:(Intercept) 3.360827 0.306726 2.759644 3.96201
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##          8         9        10        11        12        13        14
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         15        16        17        18        19        20        21
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         22        23        24        25        26        27        28
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         29        30        31        32        33        34        35
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         36        37        38        39        40        41        42
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         43        44        45        46        47        48        49
##  0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576 0.9664576
##         50
##  0.9664576
## Fitting  1990 9.15 
## List of 2
##  $ S       :'data.frame':    56 obs. of  8 variables:
##   ..$ par.index  : int [1:56] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:56] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1990": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 56 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 56 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:56] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:56] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 8 8 8 8 8 8 8 8 8 8 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  140.1545
## AICc :  142.16
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept)  3.65866 0.2324495 3.203059 4.114261
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##          8         9        10        11        12        13        14
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         15        16        17        18        19        20        21
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         22        23        24        25        26        27        28
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         29        30        31        32        33        34        35
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         36        37        38        39        40        41        42
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         43        44        45        46        47        48        49
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         50        51        52        53        54        55        56
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  140.1545
## AICc :  142.16
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept)  3.65866 0.2324495 3.203059 4.114261
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##          8         9        10        11        12        13        14
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         15        16        17        18        19        20        21
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         22        23        24        25        26        27        28
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         29        30        31        32        33        34        35
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         36        37        38        39        40        41        42
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         43        44        45        46        47        48        49
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
##         50        51        52        53        54        55        56
##  0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802 0.9748802
## Fitting  1991 12.34 
## List of 2
##  $ S       :'data.frame':    55 obs. of  8 variables:
##   ..$ par.index  : int [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:55] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1991": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 55 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 55 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:55] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 9 9 9 9 9 9 9 9 9 9 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  103.0282
## AICc :  105.0359
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.672934 0.2809117 3.122347 4.223521
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##          8         9        10        11        12        13        14
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         15        16        17        18        19        20        21
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         22        23        24        25        26        27        28
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         29        30        31        32        33        34        35
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         36        37        38        39        40        41        42
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         43        44        45        46        47        48        49
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         50        51        52        53        54        55
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  103.0282
## AICc :  105.0359
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.672934 0.2809117 3.122347 4.223521
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##          8         9        10        11        12        13        14
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         15        16        17        18        19        20        21
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         22        23        24        25        26        27        28
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         29        30        31        32        33        34        35
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         36        37        38        39        40        41        42
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         43        44        45        46        47        48        49
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
##         50        51        52        53        54        55
##  0.9752274 0.9752274 0.9752274 0.9752274 0.9752274 0.9752274
## Fitting  1992 11.56 
## List of 2
##  $ S       :'data.frame':    61 obs. of  8 variables:
##   ..$ par.index  : int [1:61] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:61] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1992": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 61 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 61 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:61] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:61] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 10 10 10 10 10 10 10 10 10 10 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  241.1084
## AICc :  243.1143
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.895561 0.1690079 2.564306 3.226817
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##          8         9        10        11        12        13        14
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         15        16        17        18        19        20        21
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         22        23        24        25        26        27        28
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         29        30        31        32        33        34        35
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         36        37        38        39        40        41        42
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         43        44        45        46        47        48        49
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         50        51        52        53        54        55        56
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         57        58        59        60        61
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  241.1084
## AICc :  243.1143
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.895561 0.1690079 2.564306 3.226817
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##          8         9        10        11        12        13        14
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         15        16        17        18        19        20        21
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         22        23        24        25        26        27        28
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         29        30        31        32        33        34        35
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         36        37        38        39        40        41        42
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         43        44        45        46        47        48        49
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         50        51        52        53        54        55        56
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
##         57        58        59        60        61
##  0.9476266 0.9476266 0.9476266 0.9476266 0.9476266
## Fitting  1993 10.56 
## List of 2
##  $ S       :'data.frame':    57 obs. of  8 variables:
##   ..$ par.index  : int [1:57] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:57] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1993": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 57 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 57 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:57] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:57] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 11 11 11 11 11 11 11 11 11 11 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  173.5447
## AICc :  175.5551
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.435438 0.1819113 2.078892 2.791984
## 
## 
## Real Parameter S
##        1       2       3       4       5       6       7       8       9
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       10      11      12      13      14      15      16      17      18
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       19      20      21      22      23      24      25      26      27
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       28      29      30      31      32      33      34      35      36
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       37      38      39      40      41      42      43      44      45
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       46      47      48      49      50      51      52      53      54
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       55      56      57
##  0.91949 0.91949 0.91949
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  173.5447
## AICc :  175.5551
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 2.435438 0.1819113 2.078892 2.791984
## 
## 
## Real Parameter S
##        1       2       3       4       5       6       7       8       9
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       10      11      12      13      14      15      16      17      18
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       19      20      21      22      23      24      25      26      27
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       28      29      30      31      32      33      34      35      36
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       37      38      39      40      41      42      43      44      45
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       46      47      48      49      50      51      52      53      54
##  0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949 0.91949
##       55      56      57
##  0.91949 0.91949 0.91949
## Fitting  1994 10.16 
## List of 2
##  $ S       :'data.frame':    43 obs. of  8 variables:
##   ..$ par.index  : int [1:43] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:43] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1994": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 43 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 43 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:43] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:43] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 12 12 12 12 12 12 12 12 12 12 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  46.86583
## AICc :  48.88574
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.251288 0.3606861 2.544343 3.958233
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##          8         9        10        11        12        13        14
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         15        16        17        18        19        20        21
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         22        23        24        25        26        27        28
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         29        30        31        32        33        34        35
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         36        37        38        39        40        41        42
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         43
##  0.9627194
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  46.86583
## AICc :  48.88574
## 
## Beta
##               estimate        se      lcl      ucl
## S:(Intercept) 3.251288 0.3606861 2.544343 3.958233
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##          8         9        10        11        12        13        14
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         15        16        17        18        19        20        21
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         22        23        24        25        26        27        28
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         29        30        31        32        33        34        35
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         36        37        38        39        40        41        42
##  0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194 0.9627194
##         43
##  0.9627194
## Fitting  1995 9.63 
## List of 2
##  $ S       :'data.frame':    42 obs. of  8 variables:
##   ..$ par.index  : int [1:42] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ model.index: num [1:42] 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ group      : Factor w/ 1 level "1995": 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ age        : Factor w/ 42 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ time       : Factor w/ 42 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##   ..$ Age        : num [1:42] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ Time       : num [1:42] 0 1 2 3 4 5 6 7 8 9 ...
##   ..$ YearF      : Factor w/ 13 levels "1983","1984",..: 13 13 13 13 13 13 13 13 13 13 ...
##  $ pimtypes:List of 1
##   ..$ S:List of 1
##   .. ..$ pim.type: chr "all"
## 
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  53.09551
## AICc :  55.12067
## 
## Beta
##               estimate        se      lcl     ucl
## S:(Intercept) 2.884334 0.3430137 2.212027 3.55664
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##          8         9        10        11        12        13        14
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         15        16        17        18        19        20        21
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         22        23        24        25        26        27        28
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         29        30        31        32        33        34        35
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         36        37        38        39        40        41        42
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
## Output summary for Nest model
## Name : S(~1) 
## 
## Npar :  1
## -2lnL:  53.09551
## AICc :  55.12067
## 
## Beta
##               estimate        se      lcl     ucl
## S:(Intercept) 2.884334 0.3430137 2.212027 3.55664
## 
## 
## Real Parameter S
##          1         2         3         4         5         6         7
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##          8         9        10        11        12        13        14
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         15        16        17        18        19        20        21
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         22        23        24        25        26        27        28
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         29        30        31        32        33        34        35
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
##         36        37        38        39        40        41        42
##  0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665 0.9470665
# Extract the nest success and create the plot
ns<- plyr::ldply(fits, function(x){
  data.frame(ns=x$ns, ns.se=x$ns.se)
})
ns$lcl <- ns$ns - 1.95*ns$ns.se
ns$ucl <- ns$ns + 1.96*ns$ns.se
ns
##    Year MayTemp        ns      ns.se        lcl       ucl
## 1  1983    8.89 0.2288284 0.06910069 0.09408203 0.3642657
## 2  1984    9.06 0.4818701 0.08535231 0.31543313 0.6491606
## 3  1985   10.60 0.4103588 0.10562422 0.20439161 0.6173823
## 4  1986   12.16 0.6648103 0.08184257 0.50521732 0.8252218
## 5  1987   10.92 0.6252834 0.09788706 0.43440360 0.8171420
## 6  1988   12.00 0.7797570 0.08675448 0.61058578 0.9497958
## 7  1989   11.89 0.5054243 0.10399939 0.30262548 0.7092631
## 8  1990    9.15 0.6012089 0.07021007 0.46429930 0.7388207
## 9  1991   12.34 0.6055058 0.08427310 0.44117322 0.7706811
## 10 1992   11.56 0.3409924 0.06036602 0.22327867 0.4593098
## 11 1993   10.56 0.1866123 0.05466127 0.08002280 0.2937484
## 12 1994   10.16 0.4677289 0.12578730 0.22244363 0.7142720
## 13 1995    9.63 0.3369844 0.12237186 0.09835929 0.5768333
ns.vs.temp <- ggplot(data=ns, aes(x=MayTemp, y=ns))+
  ggtitle("Nest success vs. May temp", subtitle="S(.) model fit to each year separately")+
  geom_point()+
  geom_errorbar(aes(ymin=lcl, ymax=ucl), width=0.01)+
  geom_smooth(method="lm")+
  ylim(0,1)
ns.vs.temp

ggsave(ns.vs.temp,
       file=file.path("..","..","..","..","MyStuff","Images","sherry-ns-vs-temp.png"),  h=4, w=6, units="in", dpi=300)

cleanup(ask=FALSE)