Skip to content

Instantly share code, notes, and snippets.

View ibartomeus's full-sized avatar

Ignasi Bartomeus ibartomeus

View GitHub Profile
@ibartomeus
ibartomeus / Parse terribly formated data
Last active June 2, 2020 23:18
Ideas on how to parse data stored as text with complex structure.
#question: Can we create an heuristic to parse this type of data:
#Input example:
Halictus crenicornis
GALICIA: 1♀, Monte do Gozo, Santiago de Compostela (La Coruña), 350 m, 5.VIII.2016, 29TNH404481. – 1♀, Río Castro, Cerdedo (Pontevedra), 20.VII.1996. – 1♀, Oca (Pontevedra), 20.VII.1996.
ASTURIAS: 1♂, 1♀, Raitán, Carreño (Asturias), 130 m, 30TTP72, 17.VIII.2005. – 1♀, Poreño, Villaviciosa (Asturias), 43,426443º, -5,445950º, 13.V.2015, sobre flor de Centaurea nigra, C. Guardado leg. – 1♀, Poreño, Villaviciosa (Asturias), 43,426443º, -5,445950º, 27.V.2014, M. Miñarro leg. – 1♀, Muñiz (Asturias), 14.VII.2016, sobre flor de Taraxacum, D. Luna leg.
#Desired output (csv):
Species, CCAA, female, male, locality, province, elevation, date, UTM, latitude, longitude, notes
Halictus crenicornis, Galicia, 1, 0, "Monte do Gozo, Santiago de Compostela", La Coruña, 350, 5.VIII.2016, 29TNH404481, NA, NA, NA
@ibartomeus
ibartomeus / random_slope_models
Created January 21, 2015 14:31
This shows how to get the random slopes and CI's for each level in a hierarchical model
#This shows how to get the random slopes and CI's for each level in a hierarchical model
#dataset used
head(iris)
#what we want to investigate
#Is there a general relationship? and how it differs by species
plot(iris$Sepal.Width ~ iris$Petal.Width, col = iris$Species, las =1)
#Our model with random slope and intercept
@ibartomeus
ibartomeus / set.R
Last active January 2, 2018 22:52
Calculate how many possible sets there are in a set game
#Calculate how many sets there are in a set game.
#each card has 4 characteristics with 3 factors each
color <- c("red", "green", "purple")
shape <- c("round", "diamond", "curly")
texture <- c("fill", "empty", "striped")
number <- c("one", "two", "three")
create_board <- function(n = 12){
@ibartomeus
ibartomeus / PowerSevilla.R
Created October 16, 2015 14:55
Talk about power analtsis for the Sevilla R users meeting
#SevillaR talk
#The problem:
time <- c(2000:2015)
abundance <- rnorm(16, 150, 50) #poison??
plot(abundance ~ time, t = "l")
#can I detect a trend?
@ibartomeus
ibartomeus / clean_species
Last active January 23, 2017 08:34
Cleaning species taxonomy using taxize. I want to correct synonyms and typo's and drop incomplete cases.
#I have >1000 bees to check its name, so I want to automatize taxize for
# fixing misspellings when possible
# updating synonims to accepted names
# keeping ONLY accepted species (fully resolved at species level)
# this uses taxize > 0.7.6.9157 If you are using older version (e.g. what its now on CRAN) see the history of this file.
library(taxize)
library(dplyr)
#example: good, synomin, typo, unexisting, genus only.
@ibartomeus
ibartomeus / origin_demo.txt
Last active June 2, 2016 14:02
OriginR demo
#This is a quick demo performed for Sevilla R users group
#Elena asked about IUCN data. You can retrive this data using taxize: https://github.com/ropensci/taxize
#Elena also suggested vectorbase can be scrapped. Maybe for the next hackaton?
#package OriginR
library(originr)
#define species (don't worry about typos)
sp <- c("Apis mellifera", "carpobrotus edulis", "Lavandula stoechas",
@ibartomeus
ibartomeus / multifunc2
Created November 1, 2013 09:31
This approach to assess multi-functionality is based in the idea that sites providing best multiple functions will have not only a high mean value across function (approach 3 in Byrnes et al.) but also low variability in the function delivered across functions (i.e. Coef of var). It assumes you have read Byrnes et al paper (http://arxiv.org/abs/…
# This approach to assess multifunctionality is based in the idea that sites providing
# best multiple functions will have not only a high mean value across function
# (approach 3 in Byrnes et al.) but also low variability in the function delivered
# across functions (i.e. Coef of var).
#I use Byrnes multifunc package to ilustrate it.
library(devtools)
install_github("multifunc", "jebyrnes")
library(multifunc)
library(ggplot2)
@ibartomeus
ibartomeus / PollinationLandscape
Last active December 14, 2015 02:19
Plot the quantity/quality pollination landscapes for tomato bee visitors in R. Inspired in Pedro Jordano's lab work (Schupp EW, Jordano P, Gómez JM (2010) New Phytol 188:333–353) https://github.com/pedroj/effectiveness
library(plotrix)
#manually enter data
d <- data.frame(
Bee_group = c("Bombus", "Dark", "Green", "Lasioglossum"),
Efficiency = c(106.86207, 81.50000, 80.66667, 59.27586),
Eff_SE = c(15.56551, 20.12130, 17.97529, 12.25689),
Visitation = c(2.8333333, 0.2222222, 2.2222222, 5.6666667),
Visit_SE = c(0.8333333, 0.1008317, 0.7119684, 1.0966378)
)
#create a grid with value x (visitation), y (efficiency) and z = x*y.
#who are the pollinators? (a plot)
#http://ibartomeus.wordpress.com/2012/12/17/who-are-the-pollinators
#enter data manually
d <- matrix(nrow = 6, ncol = 7)
d[,1] <- c(20.000, 10, 10, 10, 200.000, 100)
d[,2] <- c(6.000, 4, 8, 9, 100.000, 20)
d[,3] <- c(14.500, 6, 4, 9, 80.000, 4)
d[,4] <- c(30.000, 7, 2, 7, 50.000, 3)
d[,5] <- c(0.328, 10, 2, 3, 1.000, 5)
@ibartomeus
ibartomeus / ggplot
Created November 6, 2015 15:53
Código charlas SevillaR ggplot (Raúl Ortiz)
---
title: "Sevillarusers - ggplot2 intro"
author: "Ra?l Ortiz"
date: "Tuesday, October 27, 2015"
output: pdf_document
---
# Introducci?n al paquete gr?fico "ggplot2".
## Establezco el directorio de trabajo.