setwd("/home1/p309444/models/AIC")

library(mgcv)
library(chron)
library(lubridate)
library(lme4)
library(tidyverse)

small_phys<-read.csv("small_phys.csv",stringsAsFactors = F)

small_phys$Observer<-as.factor(small_phys$Observer)
small_phys$BirdID<-as.factor(small_phys$BirdID)
small_phys$SexEstimate<-as.factor(small_phys$SexEstimate)
small_phys$newstat<-as.factor(small_phys$newstat)


wingsubset<-gam(WingLength_z~s(age_year,k=15)+s(newlifespan)+RightTarsus_z+newstat+
              SexEstimate+avg_invert+
              s(birthyear, bs="re")+s(Observer, bs="re")+s(BirdID, bs="re"),
            data=small_phys, method = "REML", family = gaussian)



saveRDS(wingsubset, "wingsubset.rds")

