Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Binary file removed R/results/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file modified R/results/plant_results/models/adaptive_landscape_SLA_FDsnow.rds
Binary file not shown.
Binary file not shown.
Binary file modified R/results/plant_results/models/adaptive_landscape_SLA_height.rds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_FDsnow_height.rds
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_SLA_FDsnow.rds
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_SLA_deltaC13.rds
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_SLA_height.rds
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_deltaC13_FDsnow.rds
Binary file not shown.
Binary file modified R/results/plant_results/models/cfs_deltaC13_height.rds
Binary file not shown.
2 changes: 1 addition & 1 deletion R/results/plant_results/tables/disruptive_selection.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Trait","Beta","Gamma","P_Linear","P_Quadratic"
"SLA",0.0476259163621036,-0.100056733921985,0.476890961132518,0.281356584173955
"deltaC13",-0.011073134823742,-0.046034146815972,0.854663354111405,0.623298218388449
"deltaC13",-0.011073134823742,-0.046034146815972,0.854663354111406,0.623298218388449
"FDsnow",-0.13130019385937,-0.0528847820612453,0.0256334813871458,0.558628105292545
"height",-0.0674159642230305,-0.0859613170953237,0.260467489253676,0.365031981418163
Binary file not shown.
4 changes: 4 additions & 0 deletions R/results/plant_selection_results/summary_report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Analysis Date: 2026-03-21 15:57:58.057275
Families analyzed: 66
Traits analyzed: SLA, deltaC13, FDsnow, height
Significant gradients: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"SLA","Linear",-0.160116571717217,0.103086931497492,0.126436518272693,0.0106269154455685
"deltaC13","Linear",0.0763674095327287,0.0900023314895855,0.400046048707213,0.00810041967356123
"FDsnow","Linear",-0.280524291405615,0.102272093597715,0.00833401929004965,0.0104595811288598
"height","Linear",0.0434139539497148,0.0988748702319108,0.662422908307976,0.0097762399633772
"SLA²","Quadratic",-0.0118567889850557,0.192626616385609,0.951210617410946,0.0371050133401686
"deltaC13²","Quadratic",-0.326567112789641,0.147886819498291,0.032741280089733,0.0218705113813201
"FDsnow²","Quadratic",0.288612875715204,0.250518401054682,0.255811009265873,0.0627594692669945
"height²","Quadratic",-0.386993409386159,0.186210440051138,0.0438334897421209,0.0346743279840384
"SLA × deltaC13","Correlational",-0.0555686798899385,0.124124028732819,0.656679973212141,0.0154067745088657
"SLA × FDsnow","Correlational",-0.0217645341405151,0.109941142464156,0.844027264897245,0.012087054806324
"SLA × height","Correlational",0.362834513206186,0.111580467252191,0.00226453841209758,0.0124502006722173
"deltaC13 × FDsnow","Correlational",0.269017618255547,0.1035390023982,0.0128691565026352,0.0107203250176144
"deltaC13 × height","Correlational",0.0477356167768272,0.111939051625481,0.671962976755796,0.0125303512788121
"FDsnow × height","Correlational",-0.119648489345031,0.159734014382089,0.458002920741552,0.0255149553506175
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"Year","Sample_Size","Linear","Quadratic"
2012,57,-0.192876172987036,-0.119381555100731
2013,57,-0.188603788569611,0.113404451765028
2014,57,-0.0578596565616787,-0.0359199740868267
Binary file added R/results/plant_selection_results/workspace.RData
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
6 changes: 6 additions & 0 deletions R/results/test_all_functions_results/tables/bootstrap_ci.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","est","lwr","upr"
"size","Linear",0.0910165365808788,-0.470607067745545,0.494785313002583
"speed","Linear",-0.144639784052061,-0.425999225091872,0.181200243447631
"size²","Quadratic",0.402591069131511,-0.164480962378244,1.21279766762013
"speed²","Quadratic",0.0218970734483146,-0.323895558167426,0.604550913959529
"size × speed","Correlational",-0.121725317575994,-0.400589904485058,0.148398351925861
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"size","Linear",0.105036692185697,0.229833011910793,0.64766164551854,0.0528232133639866
"speed","Linear",0.31389539156892,0.232082567392143,0.176210295823653,0.0538623180873288
"size²","Quadratic",0.432724154554936,0.3338038142697,0.194857426435059,0.111424986421
"speed²","Quadratic",0.171981112711459,0.425321637062577,0.685951371316174,0.18089849495359
"size × speed","Correlational",-0.379609055590874,0.2968068107668,0.200905189547171,0.0880942829175589
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"size","Linear",0.0195027146393764,0.0477041189642697,0.683801736949462,0.0022756829661572
"speed","Linear",-0.0320661103772255,0.0477041189642697,0.503476401863023,0.00227568296615719
"size²","Quadratic",0.0837596260850392,0.0796747981055651,0.296556117916126,0.00634807345316255
"speed²","Quadratic",0.0122552368949205,0.067247096766026,0.855891235202132,0.00452217202345927
"size × speed","Correlational",-0.0374428040336,0.0525616841787993,0.478482396704399,0.00276273064371184
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","est","lwr","upr"
"TL","Linear",-1.19315987959457,-1.93852358439504,-0.675307627511643
"HL","Linear",1.02193616187728,0.528493560097037,1.74607481201091
"TL²","Quadratic",-0.803523660313887,-1.90835035323028,0.458089726463099
"HL²","Quadratic",-0.133911589615358,-1.16514233126158,0.708670236898162
"TL × HL","Correlational",0.0844408266810334,-0.933892631443336,0.816958727934413
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"TL","Linear",-0.148600056688157,0.0522929515421683,0.00448759127880404,0.00273455278099157
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"TL","Linear",-0.320470713731804,0.0747452035886859,1.80688149520203e-05,0.0055868454595141
"HL","Linear",43.9871206775832,11.2065382336764,8.66828718262568e-05,125.58649918285
"TL²","Quadratic",-0.060064537823469,0.0438384877177823,0.170645536799746,0.00192181300538215
"HL²","Quadratic",-506.68734577888,958.715009177128,0.597147669067612,919134.4688215
"TL × HL","Correlational",1.7510363861204,4.94831457272991,0.723439898989118,24.4858171106912
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"TL","Linear",-0.2505293381432,0.0793051291248291,0.00158281113461755,0.00628930350550582
"HL","Linear",57.9134440779548,13.0016414853353,8.41603336064861e-06,169.042681313192
"WT","Linear",-0.513486985805263,0.185757594440802,0.00570476374837239,0.0345058838924334
"TL²","Quadratic",-0.0423787301461475,0.0496745231276736,0.393588285551024,0.00246755824796178
"HL²","Quadratic",-446.213813331271,1228.97142425428,0.716545812020949,1510370.7616336
"WT²","Quadratic",-0.0979420091408777,0.275518724429552,0.722228359034389,0.0759105675112874
"TL × HL","Correlational",1.70003321418877,5.49482135915088,0.757026200490369,30.1930617689807
"TL × WT","Correlational",-0.0575344267982376,0.0950412225538544,0.544937919356804,0.00903283398453128
"HL × WT","Correlational",8.92035775520364,15.6101687857296,0.567697821970471,243.677369518966
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"TL","Linear",-0.320670993277407,0.0867071450740701,0.000217028959691374,0.00751812900689584
"HL","Linear",50.6908326622677,13.3806064644342,0.000151632311771967,179.040629356059
"WT","Linear",-0.693530446559714,0.20806922272575,0.00085861934246498,0.0432928014456976
"KL","Linear",21.9212334713976,7.43179129088394,0.00318127133161747,55.2315217912584
"TL²","Quadratic",-0.00797783367440701,0.0580764732264461,0.89074013175626,0.00337287674242211
"HL²","Quadratic",-624.863576259735,1250.02646782503,0.617159381022702,1562566.17026312
"WT²","Quadratic",-0.244594360801222,0.317609280557919,0.441234125899812,0.100875655096519
"KL²","Quadratic",370.460776281646,469.816611916324,0.430391383259098,220727.648832534
"TL × HL","Correlational",4.45461045018703,5.94429764120929,0.453620834279414,35.3346744472864
"TL × WT","Correlational",-0.011566779173003,0.106037263868682,0.913137284387746,0.0112439013287565
"TL × KL","Correlational",-7.21346835386392,4.23506161420698,0.0885168914226284,17.9357468761295
"HL × WT","Correlational",10.1534888398331,16.7627568835616,0.544702612937581,280.990018337392
"HL × KL","Correlational",-79.26982848486,472.990065542256,0.866903471130716,223719.602101667
"WT × KL","Correlational",6.0068916037349,8.96777928786145,0.502965882378995,80.4210653557968
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"trait","differential"
"TL",158.708333333333
"HL",0.735944444444444
"WT",25.2263888888889
"KL",0.845027777777778
Binary file not shown.
6 changes: 6 additions & 0 deletions R/results/test_extended_tests_results/tables/bootstrap_ci.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","est","lwr","upr"
"size","Linear",0.0760558821848199,-0.28684282516807,0.422172485252698
"speed","Linear",-0.024681347148765,-0.779342389158814,0.376818126567057
"size²","Quadratic",-0.182389837319528,-1.28268185489664,0.678660140549856
"speed²","Quadratic",-0.518814502983225,-1.35468930322043,0.653153946517994
"size × speed","Correlational",0.00340236207759671,-0.489466130934407,0.685313790601494
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"size","Linear",0.102235520119481,0.327332684561984,0.754790432960762,0.107146686382556
"speed","Linear",1.29260811355349,0.429605966576952,0.00262262259617551,0.184561286518517
"size²","Quadratic",0.452890996569856,0.543639470596815,0.404803941834131,0.295543873990785
"speed²","Quadratic",0.13983935898269,0.900723508521005,0.876622451362294,0.811302838802389
"size × speed","Correlational",0.467107818931824,0.535712665585419,0.383242620642065,0.286988060068635
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Term","Type","Beta_Coefficient","Standard_Error","P_Value","Variance"
"size","Linear",0.0128739186150879,0.0585959979082062,0.827051239013278,0.00343349097085851
"speed","Linear",-0.00986602522278092,0.0585959979082062,0.86701178293771,0.00343349097085851
"size²","Quadratic",-0.0610022454480119,0.107781197437072,0.574281244807887,0.0116167865209691
"speed²","Quadratic",-0.12966954826548,0.0914870314363421,0.163422019425159,0.00836987692103425
"size × speed","Correlational",0.00694577455413535,0.0717055298753092,0.923273281776424,0.00514168301469886
Binary file not shown.
6 changes: 4 additions & 2 deletions R/scripts/0.0_initialize.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ======================================================
# 0.0_initialize.R
# Project initialization script
# initialize.R
#
# Purpose:
# 1. Installs and loads all required packages
# ======================================================

cat("\n========================================\n")
Expand Down
14 changes: 12 additions & 2 deletions R/scripts/2_linear_selection_analysis.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# ============================================================================
# analyze_linear_selection
#
# Purpose: Estimate linear selection gradients (β) using Lande & Arnold (1983)
# Purpose:
# 1. Estimate linear selection gradients (β) using Lande & Arnold (1983)
#
# IMPORTANT NOTE:
# - ALWAYS use OLS (ordinary least squares) to estimate selection gradients
Expand All @@ -27,6 +28,12 @@
# 4. Type III ANOVA on GLM for overall term significance
# 5. Check VIF using OLS (GLM VIF not directly comparable)
#
# Parameters:
# data : data frame containing fitness and trait measurements
# fitness_col : name of the fitness column (character)
# trait_cols : vector of trait column names
# fitness_type : "binary" or "continuous"
#
# Returns:
# For continuous: list with model (lm), summary, anova, vif, fitness_type
# For binary: list with model (list of ols and glm), summary (list of ols and glm),
Expand All @@ -44,7 +51,10 @@
#'
#' @return A list containing the fitted models, summaries, ANOVA tables, and VIFs.
#' @export
analyze_linear_selection <- function(data, fitness_col, trait_cols, fitness_type) {
analyze_linear_selection <- function(data,
fitness_col,
trait_cols,
fitness_type) {
# Check sample size
if (nrow(data) < 10) {
warning("Small sample size (n < 10) — results may be unreliable")
Expand Down
30 changes: 20 additions & 10 deletions R/scripts/3_nonlinear_selection_analysis.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# ============================================================================
# analyze_nonlinear_selection
#
# Purpose: Estimate quadratic (γ) and correlational (γ_ij) selection gradients
# Purpose:
# 1. Estimate quadratic (γ) and correlational (γ_ij) selection gradients
#
# Model:
# w = α + β₁z₁ + β₂z₂ + ½γ₁₁z₁² + ½γ₂₂z₂² + γ₁₂z₁z₂ + ε
#
# Where:
# β = linear selection gradients
# γ_ii = quadratic selection gradients (stabilizing/disruptive)
# γ_ij = correlational selection gradients (interactions)
#
# IMPORTANT NOTE:
# - ALWAYS use OLS to estimate selection gradients (β, γ, γ_ij)
Expand All @@ -11,21 +20,19 @@
# - For continuous fitness: OLS provides both gradient estimates AND valid
# p-values (via t-tests and F-tests).
#
# Model:
# w = α + β₁z₁ + β₂z₂ + ½γ₁₁z₁² + ½γ₂₂z₂² + γ₁₂z₁z₂ + ε
#
# Where:
# - β = linear selection gradients
# - γ_ii = quadratic selection gradients (stabilizing/disruptive)
# - γ_ij = correlational selection gradients (interactions)
#
# Workflow:
# 1. Build formula with linear, quadratic, and interaction terms
# 2. Fit OLS to get all gradient estimates (β, γ, γ_ij)
# 3. For binary fitness: fit logistic GLM for valid p-values
# 4. Type III ANOVA for significance tests
# 5. VIF check for multicollinearity
#
# Parameters:
# data : data frame containing fitness and trait measurements
# fitness_col : name of the fitness column (character)
# trait_cols : vector of trait column names
# fitness_type : "binary" or "continuous"
#
# Returns:
# For continuous: list with model_ols, summary_ols, anova, vif, fitness_type
# For binary: list with model_ols, model_glm, summary_ols, summary_glm,
Expand All @@ -43,7 +50,10 @@
#'
#' @return A list containing the fitted nonlinear models, summaries, ANOVA tables, and VIFs.
#' @export
analyze_nonlinear_selection <- function(data, fitness_col, trait_cols, fitness_type) {
analyze_nonlinear_selection <- function(data,
fitness_col,
trait_cols,
fitness_type) {
if (length(trait_cols) < 2) {
stop("Nonlinear selection requires at least 2 traits")
}
Expand Down
Loading