Skip to content

Instantly share code, notes, and snippets.

View lundquist-ecology-lab's full-sized avatar

Lundquist Ecology Lab lundquist-ecology-lab

View GitHub Profile
@lundquist-ecology-lab
lundquist-ecology-lab / export_csv.r
Created February 16, 2023 18:48
Exporting data
# Exporting data as a .csv in R
write.csv(iris, "iris_export.csv", row.names = FALSE)
@lundquist-ecology-lab
lundquist-ecology-lab / subset.r
Last active February 16, 2023 18:41
How to subset data in R
# Subsetting data in R
# Subset Iris data into a dataframe with only one species
virginica <- subset(iris, iris$Species == "virginica")
# Subset a particular vector with only the values from a particular group
virginica_sepals <- iris$Sepal.Length[iris$Species == "virginica"]
@lundquist-ecology-lab
lundquist-ecology-lab / 100pct_selection.r
Last active February 1, 2023 18:12
Simulation of population under 100% selection
## Hardy Weinberg script (2)
## Simulating changes in genotype frequencies over time
## under 100% selection against homozygous recessive
## Instruction: Press "-->Source"
##################### CODE: Ignore all of this below ###########################
for (i in 1) {
@lundquist-ecology-lab
lundquist-ecology-lab / 20pct_selection.r
Created January 31, 2023 17:50
Simulation of population under 20% selection
## Hardy Weinberg script (3)
## Simulating changes in genotype frequencies over time
## under 20% selection against homozygous recessive
## Instruction: Press "-->Source"
##################### CODE: Ignore all of this below ###########################
for (i in 1) {
@lundquist-ecology-lab
lundquist-ecology-lab / under_HWE.r
Created January 31, 2023 17:50
Simulation of population under HWE
## Hardy Weinberg script (1)
## Simulating changes in genotype frequencies over time
## under Hardy-Weinberg Equilibrium
## Instruction: Press "-->Source"
##################### CODE: Ignore all of this below ###########################
BB.f <- NA
@lundquist-ecology-lab
lundquist-ecology-lab / survival.r
Last active January 27, 2023 20:29
Survival analysis and log-rank comparison in R
# Survival analysis in R
# Load library (install first if needed)
library(survival)
library(survMisc)
# create a sample data set
data <- lung
# fit a survival model
@lundquist-ecology-lab
lundquist-ecology-lab / pca.py
Last active January 25, 2023 02:46
Principal component analysis (PCA) in Python
# Running a principal components analysis (PCA) in Python
#%%
import pandas as pd
# pip install scikit-learn
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import seaborn as sns
@lundquist-ecology-lab
lundquist-ecology-lab / pca.r
Last active January 25, 2023 01:54
SImple PCA in R using iris dataset
# Running a principal components analysis (PCA) in R
# Load data
data(iris)
# Remove factors
data <- iris
# Scale data
data_scaled <- scale(data[-5])
@lundquist-ecology-lab
lundquist-ecology-lab / tensorflow.py
Last active January 17, 2023 04:58
Example using TensorFlow in Python
#Let's say we have a dataset of images of cats and dogs, and we want to train a
# model to classify them correctly. We will be using the tf.keras module, which
# provides a high-level API for building and training neural networks.
import tensorflow as tf
from tensorflow import keras
# load dataset
(x_train, y_train), (x_val, y_val) = keras.datasets.cifar10.load_data()
@lundquist-ecology-lab
lundquist-ecology-lab / ANN.py
Created January 16, 2023 22:39
Artificial neural network (ANN) example in Python
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
# Load data
iris = load_iris()
X = iris.data
y = iris.target
# Split data into training and testing sets