-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIIN_5_metaAnalysis.Rmd
1030 lines (906 loc) · 39.9 KB
/
MIIN_5_metaAnalysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "MIIN Part 5: Meta-analysis"
author: "Marissa Lee"
date: "January 21, 2015"
output: pdf_document
---
**Filename: MIIN_5_metaAnalysis.Rmd**
**This markdown file does the following tasks:**
1. Calculate global effect sizes and plot
2. Test for inclusion of categorical moderators. Where a categorical moderator is warrented, make a forest plot and conduct post-hoc Tukeys: A) Study type, B) N fixer status, C) Ecosystem type, D) Quality
3. Test for correlation between CWM traits and effect size values. Record the outcomes in a table. In cases where the slope coefficient significantly differs from 0, plot it.
```{r libraries, echo=TRUE}
#knitr::opts_chunk$set(cache=TRUE)
require(ggplot2)
require(gridExtra)
require(plyr)
require(reshape2)
require(metafor)
source('CODE/mytheme.R')
source('CODE/metaAnalysis/fxn_PrepForestPlot.R')
source('CODE/metaAnalysis/fxn_SaveQstats.R')
source('CODE/metaAnalysis/fxn_FitPlot.R')
figuresPath<-file.path(getwd()[1], "FIGURES_TABLES", "metaAnalysis") #where to put the saved plots
fig.height<-2.5 #inches
fig.width<- 2.5 #inches
fig.res<-300
dat<-read.table("DATA/DATA_SYNTHESIZED/metaDataset.txt", header=TRUE, sep="\t")
metaSummary<-read.table("DATA/metaSummary.txt", header=TRUE, sep="\t")
source('CODE/metaAnalysis/script_orderLevels.R')
#dat structure
summ<-ddply(dat, ~measCat+traitCat, summarize,
uniqueObs = length(unique(obsID)))
#summ
```
_________________________________________________________________
# 1. Calculate global effect sizes and plot
1A. Fit a nested random effects model. Model syntax is res <- rma.mv(yi, vi, random=list(~1 | paperID, ~1 | obsID), data=dat1, subset=measCat==MEASCAT[i], slab=paste(paperID,obsID, sep=","))
```{r calcGlob, echo=TRUE, warning=FALSE, message=FALSE}
#subset unique effect size data
dat1<-dat[!is.na(dat$yi),]
dat.meas<-ddply(dat1, ~obsID+measCat, summarize,
yi = unique(yi),
vi = unique(vi),
n1i<-unique(n1i),
n2i<-unique(n2i),
paperID = unique(paperID))
colnames(dat.meas)<-c('obsID','measCat','yi','vi','n1i','n2i','paperID')
#run random effects models to determine grand effect sizes and produce funnel plots
res.list<-list()
res.pubBias.list<-list()
i<-0
newfilename<-"funnelPlots.pdf"
pdf(paste(figuresPath,'globalForest',newfilename, sep='/'), width = fig.width*3, height = fig.height*3)
par(mfrow=c(3,3))
for(i in 1:length(MEASCAT)){
#subset by MEASCAT
df<-subset(dat.meas, measCat==MEASCAT[i])
#random effects model
res <- rma.mv(yi, vi,
random= ~1 | paperID/obsID,
data=df,
slab=as.character(obsID),
method='REML')
res.list[[i]]<-res
#evaluate publication bias
## funnel plot
funnel(res, main=labels[i])
## correlation between effect size and sample size
modtab<-summary(lm(yi~n1i, data=df))$coefficients
est<-round(modtab['n1i','Estimate'], digits=3)
pval<-round(modtab['n1i','Pr(>|t|)'], digits=3)
spearman.r<-round(cor(x=df$n1i, y=df$yi, method='spearman'), digits=3)
#file-drawer problem (aka fail-safe number)
res.fsn<-fsn(yi, vi, data=df)
fsnum.n<-res.fsn$fsnum
fsnum.pval<-round(res.fsn$pval, digits=3)
#save everything
res.pubBias.list[[i]]<-data.frame(MEASCAT[i], est, pval, spearman.r, fsnum.n, fsnum.pval)
#print progress
print(paste(i, 'of', length(MEASCAT)))
}
dev.off()
names(res.list)<-MEASCAT
names(res.pubBias.list)<-MEASCAT
#random effects model results
resultdf<-PrepForestPlot(res.list) #save estimates, pvalues, and prep dataframe for plotting
resultdf
newfilename<-'globalMeans.txt'
write.table(resultdf, file=paste(figuresPath,'globalForest',newfilename, sep='/'), sep='\t')
#extract QE and QM information from res.list
Qstats<-SaveQstats(res.list) #save Q stats
Qstats
newfilename<-'globalMeans_Qstats.txt'
write.table(Qstats, file=paste(figuresPath,'globalForest',newfilename, sep='/'), sep='\t')
#evaluate publication bias -- correlation table
pubBias1.tab<-ldply(res.pubBias.list)
pubBias1.tab
newfilename<-'globalMeans_pubBias1.txt'
write.table(pubBias1.tab, file=paste(figuresPath,'globalForest',newfilename, sep='/'), sep='\t')
#show that yi's are normally distributed
# Q-Q plots
dat.measP<-dat.meas
dat.measP$measCat<-factor(dat.measP$measCat, levels=MEASCAT)
levels(dat.measP$measCat)<-labels
qq<-ggplot(dat.measP, aes(sample=yi)) +
facet_wrap(~measCat, scales='free', ncol=3) +
stat_qq() + mytheme + ggtitle('QQ Plots of effect sizes')
qq
newfilename<-"globalMeans_qqPlots.pdf"
pdf(paste(figuresPath,'globalForest',newfilename, sep='/'),
width = fig.width*3, height = fig.height*3)
qq
dev.off()
```
1B. Plot the results of this study relative to previous meta-analyses
```{r calcGlob_Liao, echo=TRUE, warning=FALSE, message=FALSE, include=FALSE}
#get rid of NAs
metaSum<-metaSummary[!is.na(metaSummary$est),]
#column that indicates whether the CI overlaps 0
overlap0<-metaSum$cil<0 & metaSum$ciu>0
metaSum$NoOverlap0<-!overlap0
#fix levels
metaSum$measCat<-factor(metaSum$measCat, levels=MEASCAT)
old.study<-c('thisStudy','liao','vila','castroDiez')
STUDY<-c('This Study','Liao 2008','Vila 2011','Castro-Diez 2014')
library(plyr)
metaSum$study<-mapvalues(metaSum$study, from = old.study, to = STUDY)
metaSum$study<-factor(metaSum$study, levels=STUDY)
colnames(metaSum)[1]<-'MEASCAT'
metaSum<-merge(metaSum,measTab)
#update effect size table for plotting with ggplot
metaSum$y<-NA
CATl<-rev(levels(metaSum$MEASCAT))
i<-0
for(i in 1:length(CATl)){
metaSum[metaSum$MEASCAT==CATl[i] & metaSum$study==STUDY[4],'y']<-i-0.3
metaSum[metaSum$MEASCAT==CATl[i] & metaSum$study==STUDY[3],'y']<-i-0.1
metaSum[metaSum$MEASCAT==CATl[i] & metaSum$study==STUDY[2],'y']<-i+0.1
metaSum[metaSum$MEASCAT==CATl[i] & metaSum$study==STUDY[1],'y']<-i+0.3
}
cols <- c("blue","darkgray","darkgray","darkgray")
shapes <- c(16,16,1,0)
#make ggplot plot
glob.sp<-ggplot(data=metaSum, aes(x=est, y=y, label=k, color=study, shape=study)) + mytheme +
geom_point(size=2) +
geom_errorbarh(aes(xmin=cil,xmax=ciu), height=0) +
geom_vline(xintercept=0,linetype="dashed") +
xlab('Effect size (RR)') +
ylab('') +
geom_text(aes(x=ciu, y=y, hjust=-0.5, vjust=0.5),size=2.2, show_guide = FALSE) +
theme(legend.title=element_text(size=8)) +
scale_y_continuous(breaks=seq(1,length(MEASCAT)),labels=rev(labels),
limits=c(0.5,9.5), expand=c(0,0)) +
xlim(-2,2) +
scale_color_manual(name='Source',values=cols) +
scale_shape_manual(name='Source',values=shapes)
glob.sp
#save global forest plot
newfilename<-"globalForest_meta.pdf"
pdf(paste(figuresPath,'globalForest',newfilename, sep='/'), width = fig.width*1.8, height = fig.height*2.5)
glob.sp
dev.off()
```
_________________________________________________________________
# 2. Test for inclusion of categorical moderators.
2A. Fit a random-effects model with 1 of the categorical variables as a fixed effect. Model syntax is res <- rma.mv(yi, vi, mods= ~factor(Xmod), random=list(~1 | paperID, ~1 | obsID), data=dat1, subset=measCat==MEASCAT[i], slab=paste(paperID,obsID, sep=",")) where Xmod is one of the following: (1) Quality, (2) Ecosystem type, (3) Study type, (4) Invasive legumes present/absent, (5) Reference legumes present/absent
```{r calcFact, echo=TRUE, warning=FALSE, message=FALSE}
dat.meas<-ddply(dat, ~obsID+measCat, summarize,
yi = unique(yi),
vi = unique(vi),
paperID = unique(paperID),
measQuality= unique(measQuality),
ecosystCat= unique(ecosystCat),
studyType= unique(studyType),
Nfix= unique(Nfix))
dat.tmp<-dat.meas[dat.meas$measCat %in% MEASCAT,]
dat.tmp<-dat.tmp[!is.na(dat.tmp$yi),]
#look for singularities
temp<-ddply(dat.tmp, ~measCat+Nfix, summarize, n=length(paperID))
temp
which(temp$n==1)
#for the ecosystCat, remove the 'other' level from the model
dat.tmp<-dat.tmp[dat.tmp$ecosystCat != 'other',]
dat.tmp$ecosystCat<-droplevels(dat.tmp$ecosystCat)
### fit 3-level random-effects models with a categorical mod
res<-list()
res.quality<-list()
res.ecosyst<-list()
res.studytype<-list()
res.Nfix<-list()
i<-0
for(i in 1:length(MEASCAT)){
subdat<-subset(dat.tmp, measCat==MEASCAT[i])
#reduced model
res[[i]]<- rma.mv(yi, vi,
random= ~1 | paperID/obsID,
data=subdat, slab=as.character(obsID),
method='REML')
#full models
res.quality[[i]]<- rma.mv(yi, vi,
mods= ~factor(measQuality),
random= ~1 | paperID/obsID,
data=subdat, slab=as.character(obsID),
method='REML')
res.ecosyst[[i]]<- rma.mv(yi, vi,
mods= ~factor(ecosystCat),
random= ~1 | paperID/obsID,
data=subdat, slab=as.character(obsID),
method='REML')
res.studytype[[i]]<- rma.mv(yi, vi,
mods= ~factor(studyType),
random= ~1 | paperID/obsID,
data=subdat, slab=as.character(obsID),
method='REML')
res.Nfix[[i]]<- rma.mv(yi, vi,
mods= ~factor(Nfix),
random= ~1 | paperID/obsID,
data=subdat, slab=as.character(obsID),
method='REML')
print(paste(i, 'of', length(MEASCAT)))
}
names(res)<-MEASCAT
names(res.quality)<-MEASCAT
names(res.ecosyst)<-MEASCAT
names(res.studytype)<-MEASCAT
names(res.Nfix)<-MEASCAT
#Test whether inclusion of any of these moderators are warrented
ANOVAParams<-function(fullMod, reducedMod){
#do anova comparison
#anova.comp<-anova(fullMod,reducedMod)
QM<-fullMod$QM
QMp<-fullMod$QMp
#manually calculate the pseudo R2 values
#compute the proportional reduction in the variance components as a sort of pseudo R-squared value
pseudoR2.1<-(reducedMod$sigma2[1] - fullMod$sigma2[1]) / reducedMod$sigma2[1]
pseudoR2.2<-(reducedMod$sigma2[2] - fullMod$sigma2[2]) / reducedMod$sigma2[2]
pseudoR2.perc<-(sum(reducedMod$sigma2) - sum(fullMod$sigma2)) / sum(reducedMod$sigma2)
anova.comp.df<-data.frame(QM=round(QM, digits=3),
QMp=round(QMp, digits=3),
pseudoR2.1=round(pseudoR2.1, digits=3), #pseudo R2 for the 1st sigma2
pseudoR2.2=round(pseudoR2.2, digits=3), #pseudo R2 for the 2nd sigma2
pseudoR2.perc=round(pseudoR2.perc, digits=3)
)
# #put everything in a table
# anova.comp.df<-data.frame(p.f=anova.comp$p.f, #number of parameters in the full model
# LRT=round(anova.comp$LRT, digits=3), #likelihood ratio statistic
# pval=round(anova.comp$pval, digits=3), #p-value for the likelihood ratio test
# pseudoR2.1=round(pseudoR2.1, digits=3), #pseudo R2 for the 1st sigma2
# pseudoR2.2=round(pseudoR2.2, digits=3), #pseudo R2 for the 2nd sigma2
# pseudoR2.perc=round(pseudoR2.perc, digits=3) #the proportional reduction in the total variance
#)
return(anova.comp.df)
}
i<-0
tmp.list<-list()
for(i in 1:length(MEASCAT)){
# #reduced model parameters
# p.r<-anova(res.quality[[i]], res[[i]])$p.r
#full vs reduced model anova and extract params
qualityA<-ANOVAParams(fullMod=res.quality[[i]], reducedMod=res[[i]])
ecosystA<-ANOVAParams(fullMod=res.ecosyst[[i]], reducedMod=res[[i]])
studytypeA<-ANOVAParams(fullMod=res.studytype[[i]], reducedMod=res[[i]])
NfixA<-ANOVAParams(fullMod=res.Nfix[[i]], reducedMod=res[[i]])
tmpdf<-rbind(qualityA, ecosystA, studytypeA, NfixA) #same anova params in a dataframe
anovaLabels<-c('qualityA','ecosystA','studytypeA','NfixA') #name all the rows
# #add a column to hold the reduced model information
# p.rCol<-rep(p.r, dim(tmpdf)[1])
#save df
tmp.list[[i]]<-data.frame(anovaLabels, tmpdf)
}
names(tmp.list)<-MEASCAT
anovaMods<-ldply(tmp.list)
anovaMods
newfilename<-'anovaMods.txt'
write.table(anovaMods, file=paste(figuresPath,'modForests',newfilename, sep='/'), sep='\t')
```
2Bi. Study type
```{r studytype, echo=TRUE, warning=FALSE, message=FALSE}
currMeasFac<-anovaMods[anovaMods$anovaLabels=='studytypeA' & anovaMods$QMp < 0.05,'.id']
currMeasFac
#Run post-hoc comparisions among Study type levels, pull out means and CI
i<-0
posthoc.list<-list()
pred.list<-list()
for(i in 1:length(currMeasFac)){
#1. calc posthoc pvals
posthocR<-anova(res.studytype[[currMeasFac[i]]],
L=rbind(c(1,-1,0,0), #fs vs ea
c(1,0,-1,0), #fs vs er
c(1,0,0,-1), #fs vs gh
c(0,1,-1,0), #ea vs er
c(0,1,0,-1), #ea vs gh
c(0,0,1,-1) #er vs gh
))
levelcomp<-c('fs_ea','fs_er','fs_gh','ea_er','ea_gh','er_gh')
posthoc.list[[i]]<-data.frame(levelcomp, pval=round(posthocR$pval, digits=4))
#2. calc predicted values by level
predR<-predict(res.studytype[[currMeasFac[i]]])
tmp<-data.frame(obsID=predR$slab, pred=predR$pred,
cilb=predR$ci.lb, ciub=predR$ci.ub, se=predR$se)
ind.studyType<-ddply(dat.tmp, ~obsID, summarize, studyType1=unique(studyType))
tmp1<-merge(tmp, ind.studyType)
tmp2<-ddply(tmp1, ~studyType1, summarize,
pred = unique(pred),
cilb = unique(cilb),
ciub = unique(ciub),
se = unique(se),
k = length(obsID))
pred.list[[i]]<-tmp2
}
names(posthoc.list)<-currMeasFac
posthocR<-ldply(posthoc.list)
posthocR
names(pred.list)<-currMeasFac
predR<-ldply(pred.list)
predR
#update effect size table for plotting
colnames(predR)[1]<-'MeasFac'
selectMeas<-unique(predR$MeasFac)
MeasFacl<-rev(levels(factor(MEASCAT[MEASCAT %in% selectMeas], levels=MEASCAT[MEASCAT %in% selectMeas])))
MeasNamesl<-rev(measTab[measTab$MEASCAT %in% selectMeas,'labels'])
colnames(predR)[2]<-'CAT'
CAT<-levels(dat$studyType)
predR$y<-NA
i<-0
for(i in 1:length(MeasFacl)){
predR[predR$CAT==CAT[1] & predR$MeasFac==MeasFacl[i],'y']<-i+0.3
predR[predR$CAT==CAT[2] & predR$MeasFac==MeasFacl[i],'y']<-i+0.1
predR[predR$CAT==CAT[3] & predR$MeasFac==MeasFacl[i],'y']<-i-0.1
predR[predR$CAT==CAT[4] & predR$MeasFac==MeasFacl[i],'y']<-i-0.3
}
predR
#assign post-hoc letters (order:field study, expt addition, expt removl, gh)
#subset(posthocR, .id=='biom')
phTno<-c('a','b','b','b')
phTsom<-c('a','ab','ab','b')
predR$posthocL<-c(phTno,phTsom)
#assign pretty names and symbols
faclimits<-rev(c('Greenhouse study',
'Field removal',
'Field addition',
'Field observation'))
facShapes<-c(16,17,15,18)
predR$annLabel<-paste(predR$posthocL, ' (',predR$k,')', sep='')
#ggplot
predR1<-predR #get rid of the CIs for a level with only 1 data point
predR1[predR1$MeasFac == 'som' & predR1$CAT == 'field expt addition',c('cilb','ciub')]<-NA
stud.sp<-ggplot(data=predR1,aes(x=pred,y=y, shape=CAT, label=annLabel)) +
geom_point(aes(shape=CAT),size=2) +
geom_errorbarh(aes(xmin=cilb,xmax=ciub), height=0)+
geom_vline(xintercept=0,linetype="dashed") + mytheme +
xlab('Std. Mean Diff. (Inv-Ref)') + ylab('') +
scale_y_continuous(breaks=c(1,2),labels=MeasNamesl) +
scale_shape_manual(name="Study design",
labels=faclimits,
values=facShapes)+
geom_text(aes(x=ciub, y=y, hjust=-0.3, vjust=0.5),size=2.2,show_guide = FALSE) +
annotate("text", x=1, y=1.1, label=' (1)', size=2.2)+ #manually add the posthoc letters and k here
scale_x_continuous(expand=c(0,0), limits=c(-1.5,5.3)) +
theme(legend.title=element_text(size=8))
stud.sp
#theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
newfilename<-"studytypeForest.pdf"
pdf(paste(figuresPath,'modForests',newfilename, sep='/'), width = fig.width*1.8, height = fig.height*1)
stud.sp
dev.off()
```
2Bii. Nfix status
```{r nfix, echo=TRUE, warning=FALSE, message=FALSE}
currMeasFac<-anovaMods[anovaMods$anovaLabels=='NfixA' & anovaMods$QMp < 0.05,'.id']
currMeasFac
#levels(dat.tmp$Nfix) #check to make sure that this lines up with the way I organized the contrasts
#Run post-hoc comparisions among Nfix levels, pull out means and CI
i<-0
posthoc.list<-list()
pred.list<-list()
for(i in 1:length(currMeasFac)){
#1. calc posthoc pvals
posthocR<-anova(res.Nfix[[currMeasFac[i]]],
L=rbind(c(1,-1,0,0), #I-R- vs I-R+
c(1,0,-1,0), #I-R- vs I+R-
c(1,0,0,-1), #I-R- vs I+R+
c(0,1,-1,0), #I-R+ vs I+R-
c(0,1,0,-1), #I-R+ vs I+R+
c(0,0,1,-1) #I+R- vs I+R+
))
levelcomp<-c('none_r','none_i','none_both','r_i','r_both','i_both')
posthoc.list[[i]]<-data.frame(levelcomp, pval=round(posthocR$pval, digits=4))
#2. calc predicted values by level
predR<-predict(res.Nfix[[currMeasFac[i]]])
tmp<-data.frame(obsID=predR$slab, pred=predR$pred, cilb=predR$ci.lb, ciub=predR$ci.ub, se=predR$se)
ind.Fac<-ddply(dat.tmp, ~obsID, summarize, Level=unique(Nfix))
tmp1<-merge(tmp, ind.Fac)
tmp2<-ddply(tmp1, ~Level, summarize,
pred = unique(pred),
cilb = unique(cilb),
ciub = unique(ciub),
se = unique(se),
k = length(obsID))
pred.list[[i]]<-tmp2
}
names(posthoc.list)<-currMeasFac
posthocR<-ldply(posthoc.list)
posthocR
names(pred.list)<-currMeasFac
predR<-ldply(pred.list)
predR
#update effect size table for plotting
colnames(predR)[1]<-'MeasFac'
selectMeas<-unique(predR$MeasFac)
MeasFacl<-rev(levels(factor(MEASCAT[MEASCAT %in% selectMeas], levels=MEASCAT[MEASCAT %in% selectMeas])))
MeasNamesl<-rev(measTab[measTab$MEASCAT %in% selectMeas,'labels'])
colnames(predR)[2]<-'CAT'
CAT<-levels(dat$Nfix)
predR$y<-NA
i<-0
for(i in 1:length(MeasFacl)){
predR[predR$CAT==CAT[1] & predR$MeasFac==MeasFacl[i],'y']<-i+0.3
predR[predR$CAT==CAT[2] & predR$MeasFac==MeasFacl[i],'y']<-i+0.1
predR[predR$CAT==CAT[3] & predR$MeasFac==MeasFacl[i],'y']<-i-0.1
predR[predR$CAT==CAT[4] & predR$MeasFac==MeasFacl[i],'y']<-i-0.3
}
predR
#assign post-hoc letters (order:field study, expt addition, expt removl, gh)
#subset(posthocR, .id=='litterbiom')
phTtoti<-c('b','a','b','ab')
phTsoiln<-c('a','ab','b','ab')
phTsoilcn<-c('a','b','a','a')
predR$posthocL<-c(phTtoti,phTsoiln, phTsoilcn)
#assign pretty names and symbols
faclimits<-unique(predR$CAT)
facShapes<-c(16,17,15,18)
predR$annLabel<-paste(predR$posthocL, ' (',predR$k,')', sep='')
#ggplot
faclimits_new<-c('No N-fixers','Ref. community N-fixers only','Invasive sp. N-fixers only','Ref. and inv. sp. N-fixers')
nfix.sp<-ggplot(data=predR,aes(x=pred,y=y, shape=CAT,label=annLabel)) +
geom_point(aes(shape=CAT),size=3) +
geom_errorbarh(aes(xmin=cilb,xmax=ciub), height=0)+
geom_vline(xintercept=0,linetype="dashed") + mytheme +
xlab('Std. Mean Diff. (Inv-Ref)') + ylab('') +
scale_y_continuous(breaks=seq(1,length(MeasFacl)),
labels=MeasNamesl) +
scale_shape_manual(name="N-fixing status",
labels=faclimits_new,
values=facShapes)+
geom_text(aes(x=ciub, y=y, hjust=-0.3, vjust=0.5),size=2.2,show_guide = FALSE) +
scale_x_continuous(expand=c(0,0), limits=c(-1.3,2.3))+
theme(legend.title=element_text(size=8))
nfix.sp
#theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
newfilename<-"nfixForest.pdf"
pdf(paste(figuresPath,'modForests',newfilename, sep='/'), width = fig.width*2, height = fig.height*1.5)
nfix.sp
dev.off()
```
2Biii. Quality
```{r quality, echo=TRUE, warning=FALSE, message=FALSE}
currMeasFac<-anovaMods[anovaMods$anovaLabels=='qualityA' & anovaMods$pval < 0.05,'.id']
currMeasFac
#note - som doesn't have all levels of measQuality, so you need to have a different set of contrasts
#levels(dat.tmp$measQuality) #check to make sure that this lines up with the way I organized the contrasts
#Run post-hoc comparisions among Nfix levels, pull out means and CI
# i<-0
# posthoc.list<-list()
# pred.list<-list()
# for(i in 1:length(currMeasFac)){
# #1. calc posthoc pvals
# if(i %in% c(1,2)){
# posthocR<-anova(res.quality[[currMeasFac[i]]],
# # A+C+, A+C-, A-C+, A-C-
# L=rbind(c(1,-1,0,0), #A+C+ vs A+C-
# c(1,0,-1,0), #A+C+ vs A-C+
# c(1,0,0,-1), #A+C+ vs A-C-
# c(0,1,-1,0), #A+C- vs A-C+
# c(0,1,0,-1), #A+C- vs A-C-
# c(0,0,1,-1) #A-C+ vs A-C-
# ))
# levelcomp<-c('both_a','both_c','both_none','a_c','a_none','c_none')
# posthoc.list[[i]]<-data.frame(levelcomp, pval=round(posthocR$pval, digits=4))
# }else{
# temp1<-subset(dat.tmp, measCat=='som')
# unique(temp1$measQuality)
# #levels: A+C-, A-C+, A-C-
# posthocR<-anova(res.quality[[currMeasFac[i]]],
# L=rbind(c(1,-1,0), #A+C- vs A-C+
# c(1,0,-1), #A+C- vs A-C-
# c(0,1,-1) #A-C+ vs A-C-
# ))
# levelcomp<-c('a_c','a_none','c_none')
# posthoc.list[[i]]<-data.frame(levelcomp, pval=round(posthocR$pval, digits=4))
# }
#
# #2. calc predicted values by level
# predR<-predict(res.quality[[currMeasFac[i]]])
# tmp<-data.frame(obsID=predR$slab, pred=predR$pred, cilb=predR$ci.lb, ciub=predR$ci.ub, se=predR$se)
# ind.Fac<-ddply(dat.tmp, ~obsID+measCat, summarize, Level=measQuality)
# ind.Fac.sub<-subset(ind.Fac, measCat==currMeasFac[i])
# tmp1<-merge(tmp, ind.Fac.sub)
# tmp2<-ddply(tmp1, ~Level, summarize,
# pred = unique(pred),
# cilb = unique(cilb),
# ciub = unique(ciub),
# se = unique(se),
# k = length(obsID))
# pred.list[[i]]<-tmp2
#
# }
# names(posthoc.list)<-currMeasFac
# posthocR<-ldply(posthoc.list)
# posthocR
#
# names(pred.list)<-currMeasFac
# predR<-ldply(pred.list)
# predR
#
# #update effect size table for plotting
# colnames(predR)[1]<-'MeasFac'
# selectMeas<-unique(predR$MeasFac)
# MeasFacl<-rev(levels(factor(MEASCAT[MEASCAT %in% selectMeas], levels=MEASCAT[MEASCAT %in% selectMeas])))
# MeasNamesl<-rev(measTab[measTab$MEASCAT %in% selectMeas,'labels'])
# colnames(predR)[2]<-'CAT'
# CAT<-levels(dat$measQuality)
# predR$y<-NA
# i<-0
# for(i in 1:length(MeasFacl)){
# predR[predR$CAT==CAT[1] & predR$MeasFac==MeasFacl[i],'y']<-i+0.3
# predR[predR$CAT==CAT[2] & predR$MeasFac==MeasFacl[i],'y']<-i+0.1
# predR[predR$CAT==CAT[3] & predR$MeasFac==MeasFacl[i],'y']<-i-0.1
# predR[predR$CAT==CAT[4] & predR$MeasFac==MeasFacl[i],'y']<-i-0.3
# }
# predR
#
# #assign post-hoc letters (order ex:both, a, c, none)
# #subset(posthocR, .id=='som')
# phTnitrif<-c('','','','') #both vs c is marginally signif (p=0.059)
# phTnminz<-c('ab','ab','b','a') #both vs c is marginally signif (p=0.080), c vs none is signif (p=0.038)
# phTsom<-c('ab','a','b') #c vs none pval=0.0128
# predR$posthocL<-c(phTnitrif,phTnminz, phTsom)
#
# #assign pretty names and symbols
# faclimits<-rev(c('No Manipulation','Units Converted',
# 'Values Aggregated','Units Converted &\nValues Aggregated'))
# facShapes<-c(16,17,15,18)
# predR$annLabel<-paste(predR$posthocL, ' (',predR$k,')', sep='')
#
# #ggplot
# qual.sp<-ggplot(data=predR,aes(x=pred,y=y, shape=CAT,label=annLabel)) +
# geom_point(aes(shape=CAT),size=3) +
# geom_errorbarh(aes(xmin=cilb,xmax=ciub), height=0)+
# geom_vline(xintercept=0,linetype="dashed") + mytheme +
# xlab('Std. Mean Diff. (Inv-Ref)') + ylab('') +
# scale_shape_manual(name="Factor",
# labels=faclimits,
# values=facShapes) +
# scale_y_continuous(breaks=seq(1,length(MeasFacl)),
# labels=MeasNamesl) +
# geom_text(aes(x=ciub, y=y, hjust=-0.3, vjust=0.5),size=2.2,show_guide = FALSE) +
# scale_x_continuous(expand=c(0,0),limits=c(-3,2.3))
# qual.sp + theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
#
# newfilename<-"qualityForest.png"
# png(paste(figuresPath,'modForests',newfilename, sep='/'), units='in', width = fig.width*2, height = fig.height*2, res=fig.res)
# qual.sp + theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
# dev.off()
```
2Biv. Ecosystem type
```{r ecosyst, echo=TRUE, warning=FALSE, message=FALSE}
currMeasFac<-anovaMods[anovaMods$anovaLabels=='ecosystA' & anovaMods$pval < 0.05,'.id']
currMeasFac
# #levels(dat.tmp$ecosystCat) #check to make sure that this lines up with the way I organized the contrasts
# #Run post-hoc comparisions among Nfix levels, pull out means and CI
# i<-0
# posthoc.list<-list()
# pred.list<-list()
# for(i in 1:length(currMeasFac)){
# #1. calc posthoc pvals
# # forest, shrubland, grassland, wetland
# posthocR<-anova(res.ecosyst[[currMeasFac[i]]],
# L=rbind(c(1,-1,0,0), #forest vs shrub
# c(1,0,-1,0), #forest vs grass
# c(1,0,0,-1), #forest vs wet
# c(0,1,-1,0), #shrub vs grass
# c(0,1,0,-1), #shrub vs wet
# c(0,0,1,-1) #grass vs wet
# ))
# levelcomp<-c('f_s','f_g','f_w',
# 's_g','s_w',
# 'g_w')
# posthoc.list[[i]]<-data.frame(levelcomp, pval=round(posthocR$pval, digits=4))
# #2. calc predicted values by level
# predR<-predict(res.ecosyst[[currMeasFac[i]]])
# tmp<-data.frame(obsID=predR$slab, pred=predR$pred, cilb=predR$ci.lb, ciub=predR$ci.ub, se=predR$se)
# ind.Fac<-ddply(dat.tmp, ~obsID, summarize, Level=unique(ecosystCat))
# tmp1<-merge(tmp, ind.Fac)
# tmp2<-ddply(tmp1, ~Level, summarize,
# pred = unique(pred),
# cilb = unique(cilb),
# ciub = unique(ciub),
# se = unique(se),
# k = length(obsID))
# pred.list[[i]]<-tmp2
# }
# names(posthoc.list)<-currMeasFac
# posthocR<-ldply(posthoc.list)
# posthocR
#
# names(pred.list)<-currMeasFac
# predR<-ldply(pred.list)
# predR
#
# #update effect size table for plotting
# colnames(predR)[1]<-'MeasFac'
# selectMeas<-unique(predR$MeasFac)
# MeasFacl<-rev(levels(factor(MEASCAT[MEASCAT %in% selectMeas], levels=MEASCAT[MEASCAT %in% selectMeas])))
# MeasNamesl<-rev(measTab[measTab$MEASCAT %in% selectMeas,'labels'])
# colnames(predR)[2]<-'CAT'
# CAT<-levels(dat.tmp$ecosystCat)
# predR$y<-NA
# i<-0
# for(i in 1:length(MeasFacl)){
# predR[predR$CAT==CAT[1] & predR$MeasFac==MeasFacl[i],'y']<-i+0.3
# predR[predR$CAT==CAT[2] & predR$MeasFac==MeasFacl[i],'y']<-i+0.1
# predR[predR$CAT==CAT[3] & predR$MeasFac==MeasFacl[i],'y']<-i-0.1
# predR[predR$CAT==CAT[4] & predR$MeasFac==MeasFacl[i],'y']<-i-0.3
# }
# predR
#
# #assign post-hoc letters (order:f, s, g, w)
# #subset(posthocR, .id=='soiln')
# phTammonif<-c('a','b','b','b')
# phTsoiln<-c('b','bc','a','ac') #check this one
# predR$posthocL<-c(phTammonif,phTsoiln)
#
# #assign pretty names and symbols
# faclimits<-rev(c('Wetland','Grassland','Shrubland','Forest'))
# facShapes<-c(16,17,15,18)
# predR$annLabel<-paste(predR$posthocL, ' (',predR$k,')', sep='')
#
# #ggplot
# eco.sp<-ggplot(data=predR,aes(x=pred,y=y, shape=CAT,label=annLabel)) +
# geom_point(aes(shape=CAT),size=3) +
# geom_errorbarh(aes(xmin=cilb,xmax=ciub), height=0)+
# geom_vline(xintercept=0,linetype="dashed") + mytheme +
# xlab('Std. Mean Diff. (Inv-Ref)') + ylab('') +
# scale_y_continuous(breaks=seq(1,length(MeasFacl)),
# labels=MeasNamesl) +
# scale_shape_manual(name="Factor",
# labels=faclimits,
# values=facShapes)+
# geom_text(aes(x=ciub, y=y, hjust=-0.3, vjust=0.5),size=2.2,show_guide = FALSE) +
# scale_x_continuous(expand=c(0,0), limits=c(-1.1,2))
# eco.sp + theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
#
# newfilename<-"ecosystForest.png"
# png(paste(figuresPath,'modForests',newfilename, sep='/'), units='in', width = fig.width*1.5, height = fig.height*1.5, res=fig.res)
# eco.sp + theme(axis.text.y=element_text(angle=90, hjust=0.5, size=10))
# dev.off()
```
_________________________________________________________________
# 3. Test for correlation between CWM traits and effect size values
3A. Fit a random-effects model with 1 of the continuous trait variables as a fixed effect. Model syntax is res <- rma.mv(yi, vi, mods= ~Xmod, random=list(~1 | paperID, ~1 | obsID), data=dat1, subset=measCat==MEASCAT[i], slab=paste(paperID,obsID, sep=",")) where Xmod is one of the following 12 combinations:
-> 1 of 3 plant communities: (1) InvSpInvArea_cwm, (2) NatArea_cwm, (3) CWMDiff_cwm
-> 1 of 4 trait types: (1) percN, (2) litterpercN, (3) cn, (4) littercn
where...
'InvSpInvArea_cwm' is the invasive species community weighted mean trait value;
'NatArea_cwm' is the reference area plant community weighted mean trait value;
'CWMDiff_cwm' is the dissimilarity between the Invaded - Reference area plant community weighted mean trait value;
'percN' is leaf %N;
'litterpercN' is litter %N;
'cn' is leaf C:N;
'littercn' is litter C:N;
```{r fitreg, echo=TRUE, warning=FALSE, message=FALSE}
INVlist<-FitPlot(dat, k=1, qualColumn='InvSpInvArea_qualRank', colorN=5)
NATlist<-FitPlot(dat, k=2, qualColumn='NatArea_qualRank', colorN=5)
DIFFlist<-FitPlot(dat, k=3, qualColumn='CWMDiff_qualRank', colorN=10)
DIFF2list<-FitPlot(dat, k=4, qualColumn='CWMDiff2_qualRank', colorN=10)
#same thing, but instead color plots by invasive species' N-fixing status instead of trait quality
source('CODE/metaAnalysis/fxn_FitPlot_Nfix.R')
INVlist_Nfix<-FitPlot_Nfix(dat, k=1, nfixColumn='Nfix')
DIFFlist_Nfix<-FitPlot_Nfix(dat, k=3, nfixColumn='Nfix')
DIFF2list_Nfix<-FitPlot_Nfix(dat, k=4, nfixColumn='Nfix')
INVtab<-rbind(ldply(INVlist[['results']][['percN']]),
ldply(INVlist[['results']][['litterpercN']]),
ldply(INVlist[['results']][['cn']]),
ldply(INVlist[['results']][['littercn']]))[,-1]
NATtab<-rbind(ldply(NATlist[['results']][['percN']]),
ldply(NATlist[['results']][['litterpercN']]),
ldply(NATlist[['results']][['cn']]),
ldply(NATlist[['results']][['littercn']]))[,-1]
DIFFtab<-rbind(ldply(DIFFlist[['results']][['percN']]),
ldply(DIFFlist[['results']][['litterpercN']]),
ldply(DIFFlist[['results']][['cn']]),
ldply(DIFFlist[['results']][['littercn']]))[,-1]
DIFF2tab<-rbind(ldply(DIFF2list[['results']][['percN']]),
ldply(DIFF2list[['results']][['litterpercN']]),
ldply(DIFF2list[['results']][['cn']]),
ldply(DIFF2list[['results']][['littercn']]))[,-1]
newfilename<-'INVtab.txt'
write.table(INVtab, file=paste(figuresPath,'allRegressionTable',newfilename, sep='/'), sep='\t', row.names=FALSE)
newfilename<-'NATtab.txt'
write.table(NATtab, file=paste(figuresPath,'allRegressionTable',newfilename, sep='/'), sep='\t', row.names=FALSE)
newfilename<-'DIFFtab.txt'
write.table(DIFFtab, file=paste(figuresPath,'allRegressionTable',newfilename, sep='/'), sep='\t', row.names=FALSE)
newfilename<-'DIFF2tab.txt'
write.table(DIFF2tab, file=paste(figuresPath,'allRegressionTable',newfilename, sep='/'), sep='\t', row.names=FALSE)
INVtab[INVtab$pVal <0.1 & INVtab$measType %in% MEASCAT,]
INVlist[['qual']][['percN']][['soiln']] #trait quality has a marginal influence - studies with low quality trait data tend to have higher ESs
INVlist[['qual']][['percN']][['soilcn']]
INVlist[['qual']][['litterpercN']][['soilcn']]
NATtab[NATtab$pVal <0.1 & NATtab$measType %in% MEASCAT,]
NATlist[['qual']][['cn']][['nminz']]
NATlist[['qual']][['cn']][['soilcn']]
DIFFtab[DIFFtab$pVal <0.1 & DIFFtab$measType %in% MEASCAT,]
DIFFlist[['qual']][['litterpercN']][['nh']]
DIFFlist[['qual']][['litterpercN']][['toti']]
DIFFlist[['qual']][['cn']][['toti']] #trait quality has a marginal influence - studies with low quality trait data tend to have higher ESs
DIFFlist[['qual']][['cn']][['nminz']]
DIFFlist[['qual']][['cn']][['soilcn']]
DIFFlist[['qual']][['littercn']][['nh']]
DIFFlist[['qual']][['littercn']][['toti']]
DIFFlist[['qual']][['littercn']][['nminz']]
DIFF2tab[DIFF2tab$pVal <0.1 & DIFF2tab$measType %in% MEASCAT,]
DIFF2list[['qual']][['percN']][['nh']] #trait quality has a marginal influence - studies with low quality trait data tend to have higher ESs
DIFF2list[['qual']][['litterpercN']][['soilcn']]
DIFF2list[['qual']][['cn']][['nh']] # trait quality has a influence - studies with low quality trait data tend to have higher ESs
DIFF2list[['qual']][['cn']][['nminz']]
DIFF2list[['qual']][['cn']][['soilcn']]
DIFF2list[['qual']][['littercn']][['nh']]
DIFF2list[['qual']][['littercn']][['toti']]
```
3B. Plot some/all of the regressions
3Bi. Loop through all plots: 1 page per trait type x community with 9 ES panels
```{r plotregAll, echo=TRUE, warning=FALSE, message=FALSE}
#plot notes:
#predicted values calculated based on only the fixed effects
#ci = 95% confidence interval on the fixed effect coefficients
#add panel labels
INVlist1<-AddPanelTitles(INVlist)
NATlist1<-AddPanelTitles(NATlist)
DIFFlist1<-AddPanelTitles(DIFFlist)
DIFF2list1<-AddPanelTitles(DIFF2list)
#plot and save
PLANTlist<-list(INVlist1, NATlist1, DIFFlist1, DIFF2list1)
PLANTlabel<-c('INV','NAT','DIFF','DIFF2')
xlabel.PlantText<-c('Invasive species','Reference area','Invaded - Reference area','Inv Sp. - Reference area')
xlabel.TraitText<-c('Leaf %N','Litter %N','Leaf C:N','Litter C:N')
l<-0
for(l in 1:length(PLANTlist)){
i<-0
for (i in 1:length(TRAIT)){
CURRTRAIT<-PLANTlist[[l]][[i]]
xlabel<- textGrob(paste(xlabel.PlantText[l],xlabel.TraitText[i], sep=", "), x=0.5,
y=unit(1,'lines'))
#open image file connection
newfilename<-paste(paste(PLANTlabel[l],TRAIT[i], sep="_"),'.pdf',sep="")
pdf(paste(figuresPath,'allRegressionPlots',newfilename, sep='/'),
width = fig.width*3.5, height = fig.height*3.5)
grid.arrange(
textGrob('Std. Mean Diff. (Inv-Ref)', y=0.5,x=unit(1,'lines'), rot=90), # ylabel topleft
do.call(arrangeGrob, CURRTRAIT),
textGrob(" "), #bottom left
xlabel, #bottom right
widths = unit.c(unit(2.5, "lines"), unit(1, "npc") - unit(2.5, "lines")),
heights = unit.c(unit(1, "npc") - unit(2.5, "lines"), unit(2.5, "lines")),
nrow=2, ncol=2
)
dev.off()
}
}
```
a. Invasive sp. traits
```{r plotreg_inv, echo=TRUE, warning=FALSE, message=FALSE}
newfilename<-"INVreg.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width, height = fig.height)
INVlist[['figures']][['percN']][['soiln']] +
xlab('Invasive sp. Leaf %N') + ylab('Soil N effect size')
dev.off()
#showing N-fixing status
newfilename<-"INVreg_Nfix.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width*1.75, height = fig.height)
INVlist_Nfix[['figures']][['percN']][['soiln']] +
xlab('Invasive sp. Leaf %N') + ylab('Soil N effect size')
dev.off()
#small points have large variance
#large points have small variance
```
b. Reference traits
```{r plotreg_ref, echo=TRUE, warning=FALSE, message=FALSE}
# newfilename<-"NATreg.png"
# png(paste(figuresPath,newfilename, sep='/'), units='in', width = fig.width*1.8, height = fig.height*.88, res=fig.res)
# grid.arrange(
# NATlist[['figures']][['cn']][['nminz']] +
# xlab('Ref. CWM leaf C:N') + ylab('Mineralization effect size') + ggtitle('a'),
# NATlist[['figures']][['cn']][['soilcn']] +
# xlab('Ref. CWM leaf C:N') + ylab('Soil C:N effect size') + ggtitle('b'),
# ncol=2
# )
# dev.off()
#small points have large variance
#large points have small variance
```
c. Trait dissimilarity - invaded and reference areas
```{r plotreg_diff, echo=TRUE, warning=FALSE, message=FALSE}
newfilename<-"DIFFreg.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width*2, height = fig.height*2)
grid.arrange(
DIFFlist[['figures']][['litterpercN']][['toti']] +
xlab('Inv.-Ref. CWM litter %N') + ylab('Total inorg. N effect size') + ggtitle('a'),
DIFFlist[['figures']][['littercn']][['toti']] +
xlab('Inv.-Ref. CWM litter C:N') + ylab('Total inorg. N effect size') + ggtitle('b'),
DIFFlist[['figures']][['cn']][['nminz']] +
xlab('Inv.-Ref. CWM leaf C:N') + ylab('Mineralization effect size') + ggtitle('c'),
DIFFlist[['figures']][['cn']][['soilcn']] +
xlab('Inv.-Ref. CWM leaf C:N') + ylab('Soil C:N effect size') + ggtitle('d'),
ncol=2
)
dev.off()
#colors are invaders' N-fixing status
newfilename<-"DIFFreg_Nfix.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width*2, height = fig.height*2)
grid.arrange(
DIFFlist_Nfix[['figures']][['litterpercN']][['toti']] +
xlab('Inv.-Ref. CWM litter %N') + ylab('Total inorg. N effect size') +
ggtitle('a') + guides(color=FALSE),
DIFFlist_Nfix[['figures']][['littercn']][['toti']] +
xlab('Inv.-Ref. CWM litter C:N') + ylab('Total inorg. N effect size') +
ggtitle('b')+ guides(color=FALSE),
DIFFlist_Nfix[['figures']][['cn']][['nminz']] +
xlab('Inv.-Ref. CWM leaf C:N') + ylab('Mineralization effect size') +
ggtitle('c')+ guides(color=FALSE),
DIFFlist_Nfix[['figures']][['cn']][['soilcn']] +
xlab('Inv.-Ref. CWM leaf C:N') + ylab('Soil C:N effect size') +
ggtitle('d')+ guides(color=FALSE),
ncol=2
)
dev.off()
#small points have large variance
#large points have small variance
```
d. Trait dissimilarity - comparison of plots
```{r plotreg_diff2, echo=TRUE, warning=FALSE, message=FALSE}
newfilename<-"DIFF2reg_compare.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width*2, height = fig.height*4)
grid.arrange(
DIFFlist[['figures']][['litterpercN']][['toti']] +
xlab('Inv.-Ref. CWM litter %N') + ylab('Total inorg. N effect size') +
ggtitle('a'),
DIFF2list[['figures']][['litterpercN']][['toti']] +
xlab('Inv. Sp. - Ref litter %N') + ylab('Total inorg. N effect size') +
ggtitle('b'),
DIFFlist[['figures']][['littercn']][['toti']] +
xlab('Inv.-Ref. CWM litter C : N') + ylab('Total inorg. N effect size') +
ggtitle('c'),
DIFF2list[['figures']][['littercn']][['toti']] +
xlab('Inv. Sp. - Ref litter C : N') + ylab('Total inorg. N effect size') +
ggtitle('d'),
DIFFlist[['figures']][['cn']][['nminz']] +
xlab('Inv.-Ref. CWM leaf C : N') + ylab('Mineralization effect size') +
ggtitle('e'),
DIFF2list[['figures']][['cn']][['nminz']] +
xlab('Inv. Sp. - Ref leaf C : N') + ylab('Mineralization effect size') +
ggtitle('f'),
DIFFlist[['figures']][['cn']][['soilcn']] +
xlab('Inv.-Ref. CWM leaf C : N') + ylab('Soil C : N effect size') +
ggtitle('g'),
DIFF2list[['figures']][['cn']][['soilcn']] +
xlab('Inv. Sp. - Ref leaf C : N') + ylab('Soil C : N effect size') +
ggtitle('h'),
ncol=2
)
dev.off()
#showing which are N-fixers
newfilename<-"DIFF2reg_compare_Nfix.pdf"
pdf(paste(figuresPath,newfilename, sep='/'), width = fig.width*2, height = fig.height*4)
grid.arrange(
DIFFlist_Nfix[['figures']][['litterpercN']][['toti']] +
xlab('Inv.-Ref. CWM litter %N') + ylab('Total inorg. N effect size') +
ggtitle('a')+ guides(color=FALSE),
DIFF2list_Nfix[['figures']][['litterpercN']][['toti']] +
xlab('Inv. Sp. - Ref litter %N') + ylab('Total inorg. N effect size') +
ggtitle('b')+ guides(color=FALSE),
DIFFlist_Nfix[['figures']][['littercn']][['toti']] +
xlab('Inv.-Ref. CWM litter C : N') + ylab('Total inorg. N effect size') +
ggtitle('c')+ guides(color=FALSE),