R Markdown

library(ggplot2)
library(lme4)
## Loading required package: Matrix
library(MuMIn)
library(vegan)
## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.5-7
library(emmeans)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
library(lmerTest)
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
setwd("C:/Users/jc130714/OneDrive - James Cook University/Documents/Yogi Yasutake/Honours/Post-honours/Statistics and data/Final data")
getwd()
## [1] "C:/Users/jc130714/OneDrive - James Cook University/Documents/Yogi Yasutake/Honours/Post-honours/Statistics and data/Final data"

#PCA

ReproPCA = read.csv('Repro PCA.csv', strip.white=TRUE)
head(ReproPCA)
##   Number.of.clutches.per.pair Total.number.of.eggs Clutch.size..1st.
## 1                           3                  947               320
## 2                           3                  778               216
## 3                           2                  459               239
## 4                           1                  233               233
## 5                           3                  913               323
## 6                           3                  883               364
##   Average.egg.area
## 1           5.0277
## 2           4.3568
## 3           4.8173
## 4           4.3846
## 5           4.5416
## 6           3.8513
#standardising
Repro.std = stdize(ReproPCA, centre=TRUE, scale = TRUE)
head(Repro.std)
##   z.Number.of.clutches.per.pair z.Total.number.of.eggs z.Clutch.size..1st.
## 1                     0.8735644              1.2749315           0.9286975
## 2                     0.8735644              0.6374657          -0.6303750
## 3                    -0.3743847             -0.5657980          -0.2855801
## 4                    -1.6223339             -1.4182670          -0.3755266
## 5                     0.8735644              1.1466839           0.9736707
## 6                     0.8735644              1.0335243           1.5883051
##   z.Average.egg.area
## 1          0.6478583
## 2         -0.7253050
## 3          0.2172225
## 4         -0.6684054
## 5         -0.3470659
## 6         -1.7599361
Repro.rda = rda(Repro.std)
summary(Repro.rda, display=NULL)
## 
## Call:
## rda(X = Repro.std) 
## 
## Partitioning of variance:
##               Inertia Proportion
## Total               4          1
## Unconstrained       4          1
## 
## Eigenvalues, and their contribution to the variance 
## 
## Importance of components:
##                         PC1    PC2    PC3      PC4
## Eigenvalue            2.256 1.1078 0.6232 0.013192
## Proportion Explained  0.564 0.2769 0.1558 0.003298
## Cumulative Proportion 0.564 0.8409 0.9967 1.000000
## 
## Scaling 2 for species and site scores
## * Species are scaled proportional to eigenvalues
## * Sites are unscaled: weighted dispersion equal on all dimensions
## * General scaling constant of scores:
screeplot(Repro.rda)

Repro.sites.score = (scores(Repro.rda, display='sites'))
head(Repro.sites.score)
##             PC1         PC2
## sit1 -0.8437966  0.11506770
## sit2 -0.2378545 -0.07765641
## sit3  0.3076685  0.17791421
## sit4  0.9733689 -0.41061116
## sit5 -0.7399997 -0.42432679
## sit6 -0.7237659 -1.37428992
Repro.species.score = as.data.frame(scores(Repro.rda, display='species'))
Repro.species.score$Species = rownames(Repro.species.score)
Repro.sites.score = data.frame(Repro.sites.score, ReproPCA)
#getting and adding groupings 
ReproGroup = read.csv('Repro groups.csv')
head(ReproGroup)
##   Treatment Dev.treatment Repro.treatment Family...Female SL...Female..cm.
## 1      HH-H            HH               H               A            9.074
## 2      CC-H            CC               H               A            8.548
## 3      HH-C            HH               C               A            8.500
## 4      HH-H            HH               H               E            8.280
## 5      CC-H            CC               H               A            9.096
## 6      CC-H            CC               H               C            9.338
##   Weight...Female..g. Condition...Female Family...Male SL...Male..cm.
## 1               33.20           4.443670             C          9.478
## 2               27.50           4.402903             E          8.766
## 3               27.59           4.492571             D          8.948
## 4               21.74           3.829733             A          8.894
## 5               29.60           3.933149             D          9.184
## 6               30.10           3.696621             E          8.500
##   Weight...Male..g. Condition...Male
## 1             31.90         3.746628
## 2             28.75         4.268089
## 3             29.68         4.142724
## 4             30.37         4.316715
## 5             32.40         4.182629
## 6             23.80         3.875433
Repro.sites.score2 = cbind(Repro.sites.score, ReproGroup)
head(Repro.sites.score2)
##             PC1         PC2 Number.of.clutches.per.pair Total.number.of.eggs
## sit1 -0.8437966  0.11506770                           3                  947
## sit2 -0.2378545 -0.07765641                           3                  778
## sit3  0.3076685  0.17791421                           2                  459
## sit4  0.9733689 -0.41061116                           1                  233
## sit5 -0.7399997 -0.42432679                           3                  913
## sit6 -0.7237659 -1.37428992                           3                  883
##      Clutch.size..1st. Average.egg.area Treatment Dev.treatment Repro.treatment
## sit1               320           5.0277      HH-H            HH               H
## sit2               216           4.3568      CC-H            CC               H
## sit3               239           4.8173      HH-C            HH               C
## sit4               233           4.3846      HH-H            HH               H
## sit5               323           4.5416      CC-H            CC               H
## sit6               364           3.8513      CC-H            CC               H
##      Family...Female SL...Female..cm. Weight...Female..g. Condition...Female
## sit1               A            9.074               33.20           4.443670
## sit2               A            8.548               27.50           4.402903
## sit3               A            8.500               27.59           4.492571
## sit4               E            8.280               21.74           3.829733
## sit5               A            9.096               29.60           3.933149
## sit6               C            9.338               30.10           3.696621
##      Family...Male SL...Male..cm. Weight...Male..g. Condition...Male
## sit1             C          9.478             31.90         3.746628
## sit2             E          8.766             28.75         4.268089
## sit3             D          8.948             29.68         4.142724
## sit4             A          8.894             30.37         4.316715
## sit5             D          9.184             32.40         4.182629
## sit6             E          8.500             23.80         3.875433
#making a PCA figure 
#putting the sites on the graph
g = ggplot() + geom_point(data=Repro.sites.score2, aes(y=PC2, x=PC1, shape=Treatment, colour= Treatment),  show.legend = TRUE)   + theme_classic()

#adding the arrows
g = g + geom_segment(data=Repro.species.score, aes(y=0, x=0, yend=PC2, xend=PC1), arrow = arrow(length=unit(0.3, 'lines')), show.legend = FALSE)
hjust = ifelse(Repro.species.score$PC1>0,0,1)
vjust = ifelse(Repro.species.score$PC2>0,0,1)
g = g + geom_text(data=Repro.species.score, aes(y=PC2, x=PC1, label = Species))

#now adding cross hairs and axis lines 
g = g + geom_segment(data=NULL, aes(y=-Inf, x=-0, yend=Inf, xend=0))
g = g + geom_segment(data=NULL, aes(y=0, x=-Inf, yend=0, xend=Inf))
g

#PCA linear models

#Linear regression to investigate potential maternal effects
lm.1 = lm(PC1 ~ SL...Female..cm., data=Repro.sites.score2)
summary(lm.1)
## 
## Call:
## lm(formula = PC1 ~ SL...Female..cm., data = Repro.sites.score2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.97104 -0.46093 -0.05538  0.38673  1.28677 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)        2.5458     2.9995   0.849    0.407
## SL...Female..cm.  -0.2865     0.3371  -0.850    0.407
## 
## Residual standard error: 0.6824 on 18 degrees of freedom
## Multiple R-squared:  0.03858,    Adjusted R-squared:  -0.01483 
## F-statistic: 0.7223 on 1 and 18 DF,  p-value: 0.4066
lm.2 = lm(PC1 ~ Weight...Female..g., data=Repro.sites.score2)
summary(lm.2)
## 
## Call:
## lm(formula = PC1 ~ Weight...Female..g., data = Repro.sites.score2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7702 -0.5989  0.0166  0.2897  1.5242 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)
## (Intercept)          1.59691    0.95918   1.665    0.113
## Weight...Female..g. -0.05396    0.03204  -1.684    0.109
## 
## Residual standard error: 0.6468 on 18 degrees of freedom
## Multiple R-squared:  0.1361, Adjusted R-squared:  0.08813 
## F-statistic: 2.836 on 1 and 18 DF,  p-value: 0.1094
lm.3 = lm(PC1 ~ Condition...Female, data=Repro.sites.score2)
summary(lm.3)
## 
## Call:
## lm(formula = PC1 ~ Condition...Female, data = Repro.sites.score2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.9086 -0.6730 -0.1668  0.6766  0.9823 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)
## (Intercept)          1.5074     1.2484   1.207    0.243
## Condition...Female  -0.3578     0.2942  -1.216    0.240
## 
## Residual standard error: 0.669 on 18 degrees of freedom
## Multiple R-squared:  0.07594,    Adjusted R-squared:  0.0246 
## F-statistic: 1.479 on 1 and 18 DF,  p-value: 0.2396
lm.1 = lm(PC2 ~ SL...Female..cm., data=Repro.sites.score2)
summary(lm.1)
## 
## Call:
## lm(formula = PC2 ~ SL...Female..cm., data = Repro.sites.score2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.05281 -0.35207 -0.00926  0.45363  1.04081 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)  
## (Intercept)        6.3186     2.6710   2.366   0.0294 *
## SL...Female..cm.  -0.7111     0.3002  -2.369   0.0292 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6076 on 18 degrees of freedom
## Multiple R-squared:  0.2376, Adjusted R-squared:  0.1953 
## F-statistic: 5.611 on 1 and 18 DF,  p-value: 0.02924
lm.2 = lm(PC2 ~ Weight...Female..g., data=Repro.sites.score2)
summary(lm.2)
## 
## Call:
## lm(formula = PC2 ~ Weight...Female..g., data = Repro.sites.score2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3649 -0.4158 -0.0770  0.3899  1.3537 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)
## (Intercept)          0.55181    1.02357   0.539    0.596
## Weight...Female..g. -0.01865    0.03419  -0.545    0.592
## 
## Residual standard error: 0.6903 on 18 degrees of freedom
## Multiple R-squared:  0.01625,    Adjusted R-squared:  -0.0384 
## F-statistic: 0.2974 on 1 and 18 DF,  p-value: 0.5922
lm.3 = lm(PC2 ~ Condition...Female, data=Repro.sites.score2)
summary(lm.3)
## 
## Call:
## lm(formula = PC2 ~ Condition...Female, data = Repro.sites.score2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.36762 -0.21304  0.08111  0.38227  0.85624 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)  
## (Intercept)         -2.8449     1.1092  -2.565   0.0195 *
## Condition...Female   0.6752     0.2614   2.583   0.0187 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5944 on 18 degrees of freedom
## Multiple R-squared:  0.2705, Adjusted R-squared:   0.23 
## F-statistic: 6.674 on 1 and 18 DF,  p-value: 0.01874
lm.PC1a = lm(PC1 ~ Dev.treatment* Repro.treatment, data = Repro.sites.score2)

summary(lm.PC1a)
## 
## Call:
## lm(formula = PC1 ~ Dev.treatment * Repro.treatment, data = Repro.sites.score2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.2970 -0.5162  0.0708  0.3363  1.2164 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                      -0.33895    0.25796  -1.314   0.2074  
## Dev.treatmentHH                   0.72768    0.38261   1.902   0.0753 .
## Repro.treatmentH                  0.12734    0.36480   0.349   0.7316  
## Dev.treatmentHH:Repro.treatmentH -0.06283    0.58823  -0.107   0.9163  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6319 on 16 degrees of freedom
## Multiple R-squared:  0.2673, Adjusted R-squared:  0.1299 
## F-statistic: 1.945 on 3 and 16 DF,  p-value: 0.163
anova(lm.PC1a)
## Analysis of Variance Table
## 
## Response: PC1
##                               Df Sum Sq Mean Sq F value  Pr(>F)  
## Dev.treatment                  1 2.2734 2.27342  5.6943 0.02972 *
## Repro.treatment                1 0.0519 0.05189  0.1300 0.72317  
## Dev.treatment:Repro.treatment  1 0.0046 0.00455  0.0114 0.91627  
## Residuals                     16 6.3879 0.39925                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hist(residuals(lm.PC1a), col="darkgray")

plot(fitted(lm.PC1a), residuals(lm.PC1a))

PC1EMM = (emmeans(lm.PC1a, ~ Dev.treatment*Repro.treatment) %>% as.data.frame) 
PC1EMM
##   Dev.treatment Repro.treatment     emmean        SE df   lower.CL  upper.CL
## 1            CC               C -0.3389519 0.2579553 16 -0.8857927 0.2078889
## 2            HH               C  0.3887327 0.2825759 16 -0.2103015 0.9877668
## 3            CC               H -0.2116138 0.2579553 16 -0.7584547 0.3352270
## 4            HH               H  0.4532437 0.3648039 16 -0.3201060 1.2265934
ggplot(PC1EMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic() 

lm.PC2a = lm(PC2 ~ Dev.treatment* Repro.treatment + Condition...Female, data = Repro.sites.score2)

summary(lm.PC2a)
## 
## Call:
## lm(formula = PC2 ~ Dev.treatment * Repro.treatment + Condition...Female, 
##     data = Repro.sites.score2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.94030 -0.22429  0.06101  0.35086  0.76228 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                      -1.71610    1.15359  -1.488   0.1576  
## Dev.treatmentHH                   0.07091    0.31892   0.222   0.8271  
## Repro.treatmentH                 -0.81471    0.31577  -2.580   0.0209 *
## Condition...Female                0.47245    0.24907   1.897   0.0773 .
## Dev.treatmentHH:Repro.treatmentH  0.42520    0.47153   0.902   0.3814  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5011 on 15 degrees of freedom
## Multiple R-squared:  0.5679, Adjusted R-squared:  0.4527 
## F-statistic: 4.928 on 4 and 15 DF,  p-value: 0.009724
anova(lm.PC2a)
## Analysis of Variance Table
## 
## Response: PC2
##                               Df Sum Sq Mean Sq F value   Pr(>F)   
## Dev.treatment                  1 0.2425  0.2425  0.9655 0.341383   
## Repro.treatment                1 3.4492  3.4492 13.7345 0.002113 **
## Condition...Female             1 1.0549  1.0549  4.2007 0.058316 . 
## Dev.treatment:Repro.treatment  1 0.2042  0.2042  0.8131 0.381447   
## Residuals                     15 3.7670  0.2511                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
PC2EMM = (emmeans(lm.PC2a, ~ Dev.treatment*Repro.treatment) %>% as.data.frame) 
PC2EMM
##   Dev.treatment Repro.treatment      emmean        SE df   lower.CL    upper.CL
## 1            CC               C  0.27447940 0.2218879 15 -0.1984634  0.74742224
## 2            HH               C  0.34538451 0.2244466 15 -0.1330121  0.82378111
## 3            CC               H -0.54023329 0.2085737 15 -0.9847977 -0.09566891
## 4            HH               H -0.04413309 0.2977320 15 -0.6787338  0.59046762
ggplot(PC2EMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic() 

#Regressions of maternal traits to offspring and reproduction

Parental= read.csv('Correlations parental to offspring_FINAL.csv', strip.white=TRUE)
head(Parental)
##   Tank.ID Treatment Developmental.treatment Reproductive.treatment
## 1       9      HH-H                      HH                      H
## 2      25      CC-H                      CC                      H
## 3      42      HH-C                      HH                      C
## 4      75      HH-H                      HH                      H
## 5      76      CC-H                      CC                      H
## 6      77      CC-H                      CC                      H
##   Pair.replicate Female.ID Family...Female Family.Number SL...Female..cm.
## 1              1       AHH               A             1            9.074
## 2              1      ACH2               A             1            8.548
## 3              1      AHC6               A             1            8.500
## 4              2      EHHa               E             5            8.280
## 5              2      ACH5               A             1            9.096
## 6              3      CCH1               C             3            9.338
##   Weight...Female..g. Condition...Female Male.ID Family...Male Family.Number.1
## 1               33.20           4.443670    CHH9             C               3
## 2               27.50           4.402903    ECHf             E               5
## 3               27.59           4.492571    DHCh             D               4
## 4               21.74           3.829733    AHH2             A               1
## 5               29.60           3.933149    DCHc             D               4
## 6               30.10           3.696621    ECHa             E               5
##   SL...Male..cm. Weight...Male..g. Condition...Male Total.number.of.eggs
## 1          9.478             31.90         3.746628                  947
## 2          8.766             28.75         4.268089                  778
## 3          8.948             29.68         4.142724                  459
## 4          8.894             30.37         4.316715                  233
## 5          9.184             32.40         4.182629                  913
## 6          8.500             23.80         3.875433                  883
##   Number.of.clutches.per.pair Clutch.size..1st. Average.of.Egg.area..mm2.
## 1                           3               320                    5.0277
## 2                           3               216                    4.3568
## 3                           2               239                    4.8173
## 4                           1               233                    4.3846
## 5                           3               323                    4.5416
## 6                           3               364                    3.8513
##   Average.of.Juvenile.weight..mg. Average.of.Juvenile.SL..mm.
## 1                        3.665000                    5.242800
## 2                        3.725000                    5.213400
## 3                        4.695000                    5.263000
## 4                        4.514286                    4.838714
## 5                        3.820000                    5.355600
## 6                        3.355000                    5.075150
##   Average.of.Juvenile.yolk.area..mm.2. Average.of.Fulton.s.K
## 1                             1.701300              2.547800
## 2                             1.418950              2.632600
## 3                             1.210650              3.238250
## 4                             1.132143              4.028429
## 5                             1.434800              2.489750
## 6                             1.276400              2.569600
#Linear regression to investigate potential maternal effects
lm.1 = lm(Clutch.size..1st. ~ SL...Female..cm., data=Parental)
summary(lm.1)
## 
## Call:
## lm(formula = Clutch.size..1st. ~ SL...Female..cm., data = Parental)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -104.216  -36.695    4.832   42.940   99.791 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)  
## (Intercept)       -456.78     249.58  -1.830   0.0838 .
## SL...Female..cm.    80.45      28.05   2.868   0.0102 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 56.78 on 18 degrees of freedom
## Multiple R-squared:  0.3136, Adjusted R-squared:  0.2755 
## F-statistic: 8.224 on 1 and 18 DF,  p-value: 0.01023
lm.2 = lm(Clutch.size..1st. ~ Weight...Female..g., data=Parental)
summary(lm.2)
## 
## Call:
## lm(formula = Clutch.size..1st. ~ Weight...Female..g., data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -114.44  -27.55   11.96   34.57  102.45 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)  
## (Intercept)           52.976     89.093   0.595   0.5595  
## Weight...Female..g.    6.929      2.976   2.328   0.0317 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 60.08 on 18 degrees of freedom
## Multiple R-squared:  0.2315, Adjusted R-squared:  0.1888 
## F-statistic: 5.422 on 1 and 18 DF,  p-value: 0.03174
lm.3 = lm(Clutch.size..1st. ~ Condition...Female, data=Parental)
summary(lm.3)
## 
## Call:
## lm(formula = Clutch.size..1st. ~ Condition...Female, data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -114.47  -47.60  -10.67   61.95   99.98 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)  
## (Intercept)          320.16     127.04   2.520   0.0214 *
## Condition...Female   -14.74      29.93  -0.492   0.6284  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 68.08 on 18 degrees of freedom
## Multiple R-squared:  0.01329,    Adjusted R-squared:  -0.04152 
## F-statistic: 0.2425 on 1 and 18 DF,  p-value: 0.6284
lm.1 = lm(Average.of.Egg.area..mm2. ~ SL...Female..cm., data=Parental)
summary(lm.1)
## 
## Call:
## lm(formula = Average.of.Egg.area..mm2. ~ SL...Female..cm., data = Parental)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.74644 -0.32307 -0.01939  0.28466  1.17278 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)   
## (Intercept)        6.9405     2.1428   3.239  0.00455 **
## SL...Female..cm.  -0.2509     0.2408  -1.042  0.31133   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4875 on 18 degrees of freedom
## Multiple R-squared:  0.05686,    Adjusted R-squared:  0.004465 
## F-statistic: 1.085 on 1 and 18 DF,  p-value: 0.3113
lm.2 = lm(Average.of.Egg.area..mm2. ~ Weight...Female..g., data=Parental)
summary(lm.2)
## 
## Call:
## lm(formula = Average.of.Egg.area..mm2. ~ Weight...Female..g., 
##     data = Parental)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.86639 -0.25074 -0.04564  0.27997  1.08511 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          4.32925    0.73877   5.860  1.5e-05 ***
## Weight...Female..g.  0.01291    0.02468   0.523    0.607    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4982 on 18 degrees of freedom
## Multiple R-squared:  0.01497,    Adjusted R-squared:  -0.03976 
## F-statistic: 0.2735 on 1 and 18 DF,  p-value: 0.6074
lm.3 = lm(Average.of.Egg.area..mm2. ~ Condition...Female, data=Parental)
summary(lm.3)
## 
## Call:
## lm(formula = Average.of.Egg.area..mm2. ~ Condition...Female, 
##     data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8494 -0.1910 -0.0315  0.2445  0.7583 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)   
## (Intercept)          2.7027     0.8063   3.352  0.00355 **
## Condition...Female   0.4767     0.1900   2.509  0.02189 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4321 on 18 degrees of freedom
## Multiple R-squared:  0.2591, Adjusted R-squared:  0.218 
## F-statistic: 6.296 on 1 and 18 DF,  p-value: 0.02189
lm.1 = lm(Total.number.of.eggs ~ SL...Female..cm., data=Parental)
summary(lm.1)
## 
## Call:
## lm(formula = Total.number.of.eggs ~ SL...Female..cm., data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -486.81 -149.02   30.63  211.06  395.37 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)        -391.6     1173.8  -0.334    0.743
## SL...Female..cm.    112.6      131.9   0.854    0.405
## 
## Residual standard error: 267 on 18 degrees of freedom
## Multiple R-squared:  0.0389, Adjusted R-squared:  -0.01449 
## F-statistic: 0.7285 on 1 and 18 DF,  p-value: 0.4046
lm.2 = lm(Total.number.of.eggs ~ Weight...Female..g., data=Parental)
summary(lm.2)
## 
## Call:
## lm(formula = Total.number.of.eggs ~ Weight...Female..g., data = Parental)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -572.3 -135.8  -11.7  212.2  321.3 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)
## (Intercept)            5.319    377.387   0.014    0.989
## Weight...Female..g.   20.398     12.606   1.618    0.123
## 
## Residual standard error: 254.5 on 18 degrees of freedom
## Multiple R-squared:  0.127,  Adjusted R-squared:  0.07849 
## F-statistic: 2.618 on 1 and 18 DF,  p-value: 0.123
lm.3 = lm(Total.number.of.eggs ~ Condition...Female, data=Parental)
summary(lm.3)
## 
## Call:
## lm(formula = Total.number.of.eggs ~ Condition...Female, data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -358.83 -269.77   61.99  227.05  340.05 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)
## (Intercept)           70.38     491.94   0.143    0.888
## Condition...Female   127.84     115.92   1.103    0.285
## 
## Residual standard error: 263.6 on 18 degrees of freedom
## Multiple R-squared:  0.06329,    Adjusted R-squared:  0.01125 
## F-statistic: 1.216 on 1 and 18 DF,  p-value: 0.2846
lm.1 = lm(Number.of.clutches.per.pair ~ SL...Female..cm., data=Parental)
summary(lm.1)
## 
## Call:
## lm(formula = Number.of.clutches.per.pair ~ SL...Female..cm., 
##     data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3807 -0.3522  0.1583  0.7089  0.7602 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)        3.4829     3.6080   0.965    0.347
## SL...Female..cm.  -0.1331     0.4055  -0.328    0.746
## 
## Residual standard error: 0.8208 on 18 degrees of freedom
## Multiple R-squared:  0.005951,   Adjusted R-squared:  -0.04927 
## F-statistic: 0.1078 on 1 and 18 DF,  p-value: 0.7465
lm.2 = lm(Number.of.clutches.per.pair ~ Weight...Female..g., data=Parental)
summary(lm.2)
## 
## Call:
## lm(formula = Number.of.clutches.per.pair ~ Weight...Female..g., 
##     data = Parental)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.5414 -0.3987  0.1905  0.6905  0.8218 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)
## (Intercept)          1.55768    1.20792   1.290    0.214
## Weight...Female..g.  0.02508    0.04035   0.622    0.542
## 
## Residual standard error: 0.8146 on 18 degrees of freedom
## Multiple R-squared:  0.02102,    Adjusted R-squared:  -0.03337 
## F-statistic: 0.3865 on 1 and 18 DF,  p-value: 0.542
lm.3 = lm(Number.of.clutches.per.pair ~ Condition...Female, data=Parental)
summary(lm.3)
## 
## Call:
## lm(formula = Number.of.clutches.per.pair ~ Condition...Female, 
##     data = Parental)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.22395 -0.46314 -0.02657  0.63694  1.01189 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)
## (Intercept)        -0.08599    1.42808  -0.060    0.953
## Condition...Female  0.56630    0.33650   1.683    0.110
## 
## Residual standard error: 0.7653 on 18 degrees of freedom
## Multiple R-squared:  0.136,  Adjusted R-squared:  0.08795 
## F-statistic: 2.832 on 1 and 18 DF,  p-value: 0.1097

##Individuals trait models #Egg area

EggArea = read.csv('Egg area_FINAL.csv', strip.white=TRUE)
head(EggArea)
##   Tank.ID Treatment Dev.treatment Repro.treatment Pair.replicate Female.ID
## 1     139      CC-C            CC               C              1      ACC4
## 2     139      CC-C            CC               C              1      ACC4
## 3     139      CC-C            CC               C              1      ACC4
## 4     139      CC-C            CC               C              1      ACC4
## 5     139      CC-C            CC               C              1      ACC4
## 6     139      CC-C            CC               C              1      ACC4
##   Male.ID Male.family Male.SL..mm. Male.weight..g. Male.condition Female.family
## 1     FCC           F        8.648           22.63       3.498948             A
## 2     FCC           F        8.648           22.63       3.498948             A
## 3     FCC           F        8.648           22.63       3.498948             A
## 4     FCC           F        8.648           22.63       3.498948             A
## 5     FCC           F        8.648           22.63       3.498948             A
## 6     FCC           F        8.648           22.63       3.498948             A
##   Female.SL Female.weight Condition...Female Egg.replicate Egg.area..mm2.
## 1     9.144         31.27           4.089962             1          4.659
## 2     9.144         31.27           4.089962             2          5.380
## 3     9.144         31.27           4.089962             3          5.026
## 4     9.144         31.27           4.089962             4          5.122
## 5     9.144         31.27           4.089962             5          4.631
## 6     9.144         31.27           4.089962             6          4.708
str(EggArea)
## 'data.frame':    199 obs. of  17 variables:
##  $ Tank.ID           : int  139 139 139 139 139 139 139 139 139 139 ...
##  $ Treatment         : chr  "CC-C" "CC-C" "CC-C" "CC-C" ...
##  $ Dev.treatment     : chr  "CC" "CC" "CC" "CC" ...
##  $ Repro.treatment   : chr  "C" "C" "C" "C" ...
##  $ Pair.replicate    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Female.ID         : chr  "ACC4" "ACC4" "ACC4" "ACC4" ...
##  $ Male.ID           : chr  "FCC" "FCC" "FCC" "FCC" ...
##  $ Male.family       : chr  "F" "F" "F" "F" ...
##  $ Male.SL..mm.      : num  8.65 8.65 8.65 8.65 8.65 ...
##  $ Male.weight..g.   : num  22.6 22.6 22.6 22.6 22.6 ...
##  $ Male.condition    : num  3.5 3.5 3.5 3.5 3.5 ...
##  $ Female.family     : chr  "A" "A" "A" "A" ...
##  $ Female.SL         : num  9.14 9.14 9.14 9.14 9.14 ...
##  $ Female.weight     : num  31.3 31.3 31.3 31.3 31.3 ...
##  $ Condition...Female: num  4.09 4.09 4.09 4.09 4.09 ...
##  $ Egg.replicate     : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Egg.area..mm2.    : num  4.66 5.38 5.03 5.12 4.63 ...
EggArea$Male.family = factor(EggArea$Male.family)
EggArea$Dev.treatment = factor(EggArea$Dev.treatment)
EggArea$Repro.treatment = factor(EggArea$Repro.treatment)
str(EggArea)
## 'data.frame':    199 obs. of  17 variables:
##  $ Tank.ID           : int  139 139 139 139 139 139 139 139 139 139 ...
##  $ Treatment         : chr  "CC-C" "CC-C" "CC-C" "CC-C" ...
##  $ Dev.treatment     : Factor w/ 2 levels "CC","HH": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Repro.treatment   : Factor w/ 2 levels "C","H": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Pair.replicate    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Female.ID         : chr  "ACC4" "ACC4" "ACC4" "ACC4" ...
##  $ Male.ID           : chr  "FCC" "FCC" "FCC" "FCC" ...
##  $ Male.family       : Factor w/ 5 levels "A","C","D","E",..: 5 5 5 5 5 5 5 5 5 5 ...
##  $ Male.SL..mm.      : num  8.65 8.65 8.65 8.65 8.65 ...
##  $ Male.weight..g.   : num  22.6 22.6 22.6 22.6 22.6 ...
##  $ Male.condition    : num  3.5 3.5 3.5 3.5 3.5 ...
##  $ Female.family     : chr  "A" "A" "A" "A" ...
##  $ Female.SL         : num  9.14 9.14 9.14 9.14 9.14 ...
##  $ Female.weight     : num  31.3 31.3 31.3 31.3 31.3 ...
##  $ Condition...Female: num  4.09 4.09 4.09 4.09 4.09 ...
##  $ Egg.replicate     : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Egg.area..mm2.    : num  4.66 5.38 5.03 5.12 4.63 ...
lmer.EAr = lmer(Egg.area..mm2. ~ Dev.treatment * Repro.treatment  + Condition...Female + (1|Male.family) + (1|Female.family) + (1|Egg.replicate) , data = EggArea)

summary(lmer.EAr)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## Egg.area..mm2. ~ Dev.treatment * Repro.treatment + Condition...Female +  
##     (1 | Male.family) + (1 | Female.family) + (1 | Egg.replicate)
##    Data: EggArea
## 
## REML criterion at convergence: 181.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.10972 -0.75441 -0.07345  0.65499  2.74648 
## 
## Random effects:
##  Groups        Name        Variance Std.Dev.
##  Egg.replicate (Intercept) 0.02215  0.1488  
##  Female.family (Intercept) 0.02363  0.1537  
##  Male.family   (Intercept) 0.03056  0.1748  
##  Residual                  0.11649  0.3413  
## Number of obs: 199, groups:  
## Egg.replicate, 10; Female.family, 5; Male.family, 5
## 
## Fixed effects:
##                                   Estimate Std. Error        df t value
## (Intercept)                        3.90156    0.31996  93.47974  12.194
## Dev.treatmentHH                   -0.19642    0.08149 134.69238  -2.410
## Repro.treatmentH                  -0.75511    0.08800  95.78531  -8.581
## Condition...Female                 0.24802    0.06591 156.70832   3.763
## Dev.treatmentHH:Repro.treatmentH   0.49278    0.12448 145.93574   3.959
##                                  Pr(>|t|)    
## (Intercept)                       < 2e-16 ***
## Dev.treatmentHH                  0.017290 *  
## Repro.treatmentH                 1.68e-13 ***
## Condition...Female               0.000237 ***
## Dev.treatmentHH:Repro.treatmentH 0.000117 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Dv.tHH Rpr.tH Cn...F
## Dv.trtmntHH -0.331                     
## Rpr.trtmntH -0.336  0.647              
## Cndtn...Fml -0.916  0.253  0.242       
## Dv.trHH:R.H  0.086 -0.680 -0.731 -0.008
anova(lmer.EAr)
## Type III Analysis of Variance Table with Satterthwaite's method
##                               Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
## Dev.treatment                 0.0803  0.0803     1 170.16  0.6896 0.4074750    
## Repro.treatment               8.3405  8.3405     1 156.68 71.5963 1.759e-14 ***
## Condition...Female            1.6493  1.6493     1 156.71 14.1582 0.0002371 ***
## Dev.treatment:Repro.treatment 1.8256  1.8256     1 145.94 15.6708 0.0001174 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hist(residuals(lmer.EAr), col="darkgray")

plot(fitted(lmer.EAr), residuals(lmer.EAr))

EaEMM = (emmeans(lmer.EAr, ~ Dev.treatment * Repro.treatment) %>% as.data.frame) 
EaEMM
##   Dev.treatment Repro.treatment   emmean        SE       df lower.CL upper.CL
## 1            CC               C 4.946704 0.1311469 10.85502 4.657581 5.235828
## 2            HH               C 4.750280 0.1358089 11.27185 4.452244 5.048316
## 3            CC               H 4.191595 0.1350207 11.03086 3.894518 4.488673
## 4            HH               H 4.487956 0.1424562 13.99942 4.182416 4.793495
ggplot(EaEMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic() 

##Clutch size/ number of eggs in clutch 1

ClutchSz = read.csv('Clutch size_FINAL.csv', strip.white=TRUE)
head(ClutchSz)
##   Tank.ID Treatment Dev.treatment Repro.treatment Pair.replicate Female.ID
## 1     139      CC-C            CC               C              1      ACC4
## 2     185      CC-C            CC               C              2      ACC3
## 3     190      CC-C            CC               C              3       ECC
## 4     192      CC-C            CC               C              4       ECC
## 5     197      CC-C            CC               C              5      ACCb
## 6     221      CC-C            CC               C              6      DCC4
##   Family...Female Family.Number SL...Female..cm. Weight...Female..g.
## 1               A             1            9.144               31.27
## 2               A             1            8.912               35.88
## 3               E             5            9.274               33.00
## 4               E             5            7.800               26.62
## 5               A             1            8.776               32.62
## 6               D             4            9.346               29.53
##   Condition...Female Male.ID Family...Male Family.Number.1 SL...Male..cm.
## 1           4.089962     FCC             F               6          8.648
## 2           5.069054     DCC             D               4          9.650
## 3           4.137259    ACC2             A               1          9.450
## 4           5.609501     FCC             F               6          7.738
## 5           4.826076    CCC3             C               3          8.598
## 6           3.617313    ACC5             A               1          8.814
##   Weight...Male..g. Condition...Male Clutch.size..1st.
## 1             22.63         3.498948               198
## 2             41.12         4.575844               324
## 3             36.87         4.368956               309
## 4             19.68         4.247554               123
## 5             23.61         3.714528               349
## 6             29.09         4.248392               302
ClutchSz$Tank.ID = factor(ClutchSz$Tank.ID)
str(ClutchSz)
## 'data.frame':    20 obs. of  18 variables:
##  $ Tank.ID            : Factor w/ 20 levels "9","25","42",..: 11 14 15 16 18 20 2 5 6 7 ...
##  $ Treatment          : chr  "CC-C" "CC-C" "CC-C" "CC-C" ...
##  $ Dev.treatment      : chr  "CC" "CC" "CC" "CC" ...
##  $ Repro.treatment    : chr  "C" "C" "C" "C" ...
##  $ Pair.replicate     : int  1 2 3 4 5 6 1 2 3 4 ...
##  $ Female.ID          : chr  "ACC4" "ACC3" "ECC" "ECC" ...
##  $ Family...Female    : chr  "A" "A" "E" "E" ...
##  $ Family.Number      : int  1 1 5 5 1 4 1 1 3 3 ...
##  $ SL...Female..cm.   : num  9.14 8.91 9.27 7.8 8.78 ...
##  $ Weight...Female..g.: num  31.3 35.9 33 26.6 32.6 ...
##  $ Condition...Female : num  4.09 5.07 4.14 5.61 4.83 ...
##  $ Male.ID            : chr  "FCC" "DCC" "ACC2" "FCC" ...
##  $ Family...Male      : chr  "F" "D" "A" "F" ...
##  $ Family.Number.1    : int  6 4 1 6 3 1 5 4 5 4 ...
##  $ SL...Male..cm.     : num  8.65 9.65 9.45 7.74 8.6 ...
##  $ Weight...Male..g.  : num  22.6 41.1 36.9 19.7 23.6 ...
##  $ Condition...Male   : num  3.5 4.58 4.37 4.25 3.71 ...
##  $ Clutch.size..1st.  : int  198 324 309 123 349 302 216 323 364 278 ...
lm.Csz = lm(Clutch.size..1st. ~ Dev.treatment * Repro.treatment +  SL...Female..cm., data = ClutchSz)
summary(lm.Csz)
## 
## Call:
## lm(formula = Clutch.size..1st. ~ Dev.treatment * Repro.treatment + 
##     SL...Female..cm., data = ClutchSz)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -104.69  -36.03   13.73   36.08   88.51 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                      -359.23316  300.32125  -1.196   0.2502  
## Dev.treatmentHH                   -36.77985   36.70738  -1.002   0.3322  
## Repro.treatmentH                   -0.05357   36.11106  -0.001   0.9988  
## SL...Female..cm.                   70.61517   33.72581   2.094   0.0537 .
## Dev.treatmentHH:Repro.treatmentH   30.26588   57.21414   0.529   0.6046  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 59.78 on 15 degrees of freedom
## Multiple R-squared:  0.3659, Adjusted R-squared:  0.1968 
## F-statistic: 2.164 on 4 and 15 DF,  p-value: 0.1229
anova(lm.Csz)
## Analysis of Variance Table
## 
## Response: Clutch.size..1st.
##                               Df Sum Sq Mean Sq F value  Pr(>F)  
## Dev.treatment                  1  12649 12648.5  3.5389 0.07950 .
## Repro.treatment                1   2608  2607.7  0.7296 0.40645  
## SL...Female..cm.               1  14676 14676.2  4.1062 0.06089 .
## Dev.treatment:Repro.treatment  1   1000  1000.2  0.2798 0.60455  
## Residuals                     15  53612  3574.2                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hist(residuals(lm.Csz), col="darkgray")

plot(fitted(lm.Csz), residuals(lm.Csz ))

CszEMM = (emmeans(lm.Csz, ~ Dev.treatment * Repro.treatment) %>% as.data.frame) 
CszEMM
##   Dev.treatment Repro.treatment   emmean       SE df lower.CL upper.CL
## 1            CC               C 268.2462 24.40942 15 216.2187 320.2736
## 2            HH               C 231.4663 27.49902 15 172.8535 290.0791
## 3            CC               H 268.1926 26.47412 15 211.7643 324.6208
## 4            HH               H 261.6786 35.69082 15 185.6054 337.7518
ggplot(CszEMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic() 

##Total eggs and number of clutches per pair

Totals = read.csv('Clutches per pair_FINAL.csv', strip.white=TRUE)
head(Totals)
##   Tank.ID Treatment Dev.treatment Repro.treatment Pair.replicate Female.ID
## 1       9      HH-H            HH               H              1       AHH
## 2      25      CC-H            CC               H              1      ACH2
## 3      42      HH-C            HH               C              1      AHC6
## 4      75      HH-H            HH               H              2      EHHa
## 5      76      CC-H            CC               H              2      ACH5
## 6      77      CC-H            CC               H              3      CCH1
##   Family...Female Family.Number SL...Female..cm. Weight...Female..g.
## 1               A             1            9.074               33.20
## 2               A             1            8.548               27.50
## 3               A             1            8.500               27.59
## 4               E             5            8.280               21.74
## 5               A             1            9.096               29.60
## 6               C             3            9.338               30.10
##   Condition...Female Male.ID Family...Male Family.Number.1 SL...Male..cm.
## 1           4.443670    CHH9             C               3          9.478
## 2           4.402903    ECHf             E               5          8.766
## 3           4.492571    DHCh             D               4          8.948
## 4           3.829733    AHH2             A               1          8.894
## 5           3.933149    DCHc             D               4          9.184
## 6           3.696621    ECHa             E               5          8.500
##   Weight...Male..g. Condition...Male Number.of.clutches.per.pair
## 1             31.90         3.746628                           3
## 2             28.75         4.268089                           3
## 3             29.68         4.142724                           2
## 4             30.37         4.316715                           1
## 5             32.40         4.182629                           3
## 6             23.80         3.875433                           3
##   Total.number.of.eggs
## 1                  947
## 2                  778
## 3                  459
## 4                  233
## 5                  913
## 6                  883
Totals$Tank.ID = factor(Totals$Tank.ID)
str(Totals)
## 'data.frame':    20 obs. of  19 variables:
##  $ Tank.ID                    : Factor w/ 20 levels "9","25","42",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ Treatment                  : chr  "HH-H" "CC-H" "HH-C" "HH-H" ...
##  $ Dev.treatment              : chr  "HH" "CC" "HH" "HH" ...
##  $ Repro.treatment            : chr  "H" "H" "C" "H" ...
##  $ Pair.replicate             : int  1 1 1 2 2 3 4 5 3 2 ...
##  $ Female.ID                  : chr  "AHH" "ACH2" "AHC6" "EHHa" ...
##  $ Family...Female            : chr  "A" "A" "A" "E" ...
##  $ Family.Number              : int  1 1 1 5 1 3 3 3 3 1 ...
##  $ SL...Female..cm.           : num  9.07 8.55 8.5 8.28 9.1 ...
##  $ Weight...Female..g.        : num  33.2 27.5 27.6 21.7 29.6 ...
##  $ Condition...Female         : num  4.44 4.4 4.49 3.83 3.93 ...
##  $ Male.ID                    : chr  "CHH9" "ECHf" "DHCh" "AHH2" ...
##  $ Family...Male              : chr  "C" "E" "D" "A" ...
##  $ Family.Number.1            : int  3 5 4 1 4 5 4 1 4 3 ...
##  $ SL...Male..cm.             : num  9.48 8.77 8.95 8.89 9.18 ...
##  $ Weight...Male..g.          : num  31.9 28.8 29.7 30.4 32.4 ...
##  $ Condition...Male           : num  3.75 4.27 4.14 4.32 4.18 ...
##  $ Number.of.clutches.per.pair: int  3 3 2 1 3 3 3 2 1 2 ...
##  $ Total.number.of.eggs       : int  947 778 459 233 913 883 782 700 175 367 ...
lm.TotEgg1 = lm(Total.number.of.eggs  ~ Dev.treatment * Repro.treatment  , data = Totals)
summary(lm.TotEgg1)
## 
## Call:
## lm(formula = Total.number.of.eggs ~ Dev.treatment * Repro.treatment, 
##     data = Totals)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -481.8 -136.1   -0.7  175.7  495.3 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       724.000    100.471   7.206 2.09e-06 ***
## Dev.treatmentHH                  -285.600    149.023  -1.916   0.0733 .  
## Repro.treatmentH                   -9.167    142.088  -0.065   0.9494    
## Dev.treatmentHH:Repro.treatmentH   22.433    229.110   0.098   0.9232    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 246.1 on 16 degrees of freedom
## Multiple R-squared:  0.2743, Adjusted R-squared:  0.1383 
## F-statistic: 2.016 on 3 and 16 DF,  p-value: 0.1522
anova(lm.TotEgg1)
## Analysis of Variance Table
## 
## Response: Total.number.of.eggs
##                               Df Sum Sq Mean Sq F value  Pr(>F)  
## Dev.treatment                  1 365755  365755  6.0389 0.02579 *
## Repro.treatment                1      1       1  0.0000 0.99621  
## Dev.treatment:Repro.treatment  1    581     581  0.0096 0.92322  
## Residuals                     16 969069   60567                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hist(residuals(lm.TotEgg1), col="darkgray")

plot(fitted(lm.TotEgg1), residuals(lm.TotEgg1))

TEggEMM = (emmeans(lm.TotEgg1, ~ Dev.treatment * Repro.treatment) %>% as.data.frame) 
TEggEMM
##   Dev.treatment Repro.treatment   emmean       SE df lower.CL upper.CL
## 1            CC               C 724.0000 100.4712 16 511.0105 936.9895
## 2            HH               C 438.4000 110.0607 16 205.0817 671.7183
## 3            CC               H 714.8333 100.4712 16 501.8439 927.8228
## 4            HH               H 451.6667 142.0878 16 150.4541 752.8793
ggplot(TEggEMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic() 

#Number of clutches produced over the season

lm.Clutch = lm(Number.of.clutches.per.pair  ~ Dev.treatment * Repro.treatment , data = Totals)
summary(lm.Clutch)
## 
## Call:
## lm(formula = Number.of.clutches.per.pair ~ Dev.treatment * Repro.treatment, 
##     data = Totals)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.5000 -0.6667  0.1667  0.5000  1.3333 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        2.6667     0.3146   8.477  2.6e-07 ***
## Dev.treatmentHH                   -0.6667     0.4666  -1.429    0.172    
## Repro.treatmentH                  -0.1667     0.4449  -0.375    0.713    
## Dev.treatmentHH:Repro.treatmentH  -0.1667     0.7173  -0.232    0.819    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7706 on 16 degrees of freedom
## Multiple R-squared:  0.2213, Adjusted R-squared:  0.07531 
## F-statistic: 1.516 on 3 and 16 DF,  p-value: 0.2486
anova(lm.Clutch)
## Analysis of Variance Table
## 
## Response: Number.of.clutches.per.pair
##                               Df Sum Sq Mean Sq F value  Pr(>F)  
## Dev.treatment                  1 2.4083 2.40833  4.0561 0.06114 .
## Repro.treatment                1 0.2596 0.25962  0.4372 0.51786  
## Dev.treatment:Repro.treatment  1 0.0321 0.03205  0.0540 0.81922  
## Residuals                     16 9.5000 0.59375                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hist(residuals(lm.Clutch), col="darkgray")

plot(fitted(lm.Clutch), residuals(lm.Clutch))

ClutchEMM = (emmeans(lm.Clutch, ~ Dev.treatment * Repro.treatment) %>% as.data.frame) 
ClutchEMM
##   Dev.treatment Repro.treatment   emmean        SE df  lower.CL upper.CL
## 1            CC               C 2.666667 0.3145764 16 1.9997944 3.333539
## 2            HH               C 2.000000 0.3446012 16 1.2694781 2.730522
## 3            CC               H 2.500000 0.3145764 16 1.8331277 3.166872
## 4            HH               H 1.666667 0.4448783 16 0.7235669 2.609766
ggplot(ClutchEMM, aes(x=Repro.treatment, y=emmean, colour=Dev.treatment))+ geom_point() + geom_linerange(aes (ymin = emmean - SE, ymax = emmean + SE))  +  theme_classic()