Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DrK-Lo/81054c092372aa04c115428e5d422d21 to your computer and use it in GitHub Desktop.

Select an option

Save DrK-Lo/81054c092372aa04c115428e5d422d21 to your computer and use it in GitHub Desktop.
# Code from Madeline's seascape analysis
# subset to just the high temp variable
X_hightemp <- data.frame(temp_quantile_90 = merged_data$temp_quantile_90)
str(X_hightemp) # temp_quantile_90
# run lfmm2 model - least-squares estimate that runs faster for bigger datasets than lfmm
mod_lfmm2_hightemp <- lfmm2(input = Z, # thinned SNP set
                            env = X_hightemp,
                            K = 2)
# latent factors
plot(mod_lfmm2_hightemp@U, col = “grey”, pch = 19, xlab = “Factor 1", ylab = “Factor 2”)
# run lfmm2 test on the full matrix
# we want a single test significance value for association with environment at each locus.
# test the fit of the model using a fisher test
# significance values are computed using the option {full = TRUE}.
pv_lfmm2_hightemp = lfmm2.test(object = mod_lfmm2_hightemp,
                               input = Y, # full SNP set
                               env = X_hightemp,
                               full = TRUE)$pvalues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment