Skip to content

Instantly share code, notes, and snippets.

View juanchiem's full-sized avatar
😳

Juan Edwards Molina juanchiem

😳
View GitHub Profile
@juanchiem
juanchiem / outlierRemoval.R
Created February 27, 2017 12:20 — forked from smithdanielle/outlierRemoval.R
Outlier removal in R with MAD criterion: equations taken from [Leys et al (2013)](http://www.sciencedirect.com/science/article/pii/S0022103113000668).
require(plyr)
require(dplyr)
data.outliersRemoved<-ddply(data, .(withinIV1, withinIV2), function(d){
limits.outliers = median(d$DV) + 2.5*c(-1, 1)*mad(d$DV))
d$DV[which(((d$DV - limits.outliers[1])*(limits.outliers[2] - d$DV)) <= 0)]<-NA
return(d)
})
@juanchiem
juanchiem / script_exemplo_metanalise.R
Created May 12, 2017 19:17 — forked from joaovissoci/script_exemplo_metanalise.R
example of R script for metanalysis in R
#######################################################################################
#example_metanalysis.R is licensed under a Creative Commons Attribution - Non commercial 3.0 Unported License. see full license at the end of this file.
#######################################################################################
#this script follows a combination of the guidelines proposed by Hadley Wickham http://goo.gl/c04kq as well as using the formatR package http://goo.gl/ri6ky
#if this is the first time you are conducting an analysis using this protocol, please watch http://goo.gl/DajIN while following step by step
#link to manuscript
#####################################################################################
#SETTING ENVIRONMENT
library(tidyverse)
# devtools::install_github('rensa/ggflags')
library(ggflags) # https://github.com/rensa/ggflags
library(ggrepel)
library(ggthemes)
library(gganimate)
# Hecho por Rafa @GonzalezGouveia
# Con gusto para #DatosDeMiercoles, propuesto por @R4DS_es
library(ggplot2)
ggplot(data = data.frame(x = c(-4, 6)), aes(x)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 0, sd = 1), geom = "area", fill = "#F5BB87", alpha = 0.9) +
stat_function(fun = dnorm, n = 101, args = list(mean = 2.7, sd = 1), geom = "area", fill = "#BBD4EB", alpha = 0.9) +
coord_fixed(xlim = c(-5, 7), ratio = 8, clip = "off") +
annotate("segment", x = -3.9, y = 0, xend = 6, yend = 0, color = "grey60", size = 1.3) +
annotate("segment", x = -3.5, y = -0.04, xend = -3.5, yend = 0.42, color = "grey60", size = 1.3) +
annotate("text", x = 0, y = 0.18, label = "what people\nactually do\nin R", family = "Arial Bold", color = "white", size = 5.2) +
annotate("text", x = 2.75, y = 0.18, label = "what people\nassume others\ndo in R", family = "Arial Bold", color = "white", size = 5.2) +
library(tidyverse)
library(zoo)
df <- data.frame(
date = seq(as.Date("2002-01-01"), by="1 day", length.out=50) ,
var = 100 + c(0, cumsum(runif(49, -20, 20))))
df %>%
mutate(ma5=rollmean(var,5,align='right',fill=NA))%>%
mutate(sum5=rollsum(var,2,align='right',fill=NA))%>%
pacman::p_load(tidyverse, lme4, sjPlot, car)
dat <- read_csv("https://github.com/juanchiem/agro_data/raw/master/yield_wheat19.csv")
#Acondicionamiento del dataset
red_t=c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L)
id_trt <- tibble::tribble(
~trt, ~trat, ~kg_trigo,
1, "1.Check", 0,
2, "2.MD_z32", 172,
library(tidyverse)
dat <- expand.grid(sev = seq(0.01, 0.99, 0.01),
inc = seq(0.01, 0.99, 0.01)) %>%
mutate(int = inc*sev)
dat %>%
ggplot(aes(inc, sev, fill= int)) +
geom_tile() +
viridis::scale_fill_viridis(discrete=FALSE, direction = -1)+
library(tidyverse)
library(ggforce)
tibble::tribble(
~patogeno, ~hum_min, ~hum_max, ~temp_min, ~temp_max,
"RE",3L,6L,8L,14L,
"RH",6L,10L,18L,25L,
"RT",8L,12L,20L,30L,
"MA",28L,32L,18L,28L,
"SEP",72L,96L,10L,15L) %>%
library(tidyverse)
library(googlesheets4)
library(gapminder)
gs4_deauth()
red <- gs4_get("1HSoj5M--kcW-WioiwMbbngrqdkSC-bqpumeDIIlbx18")
gs4_browse(red)
# red %>% sheet_names() %>%
# map_df(~ read_sheet(red, sheet = .)) %>%
library(tidyverse)
library(googlesheets4)
gapminder <- gs4_get("https://docs.google.com/spreadsheets/d/1U6Cf_qEOhiR9AZqTqS3mbMF3zt2db48ZP5v3rkrAEJY/edit#gid=780868077")
# gapminder es una planilla de google sheets que tiene 5 hojas (una por continente)
# Cuando cada hoja tiene toda la información que necesitamos (como este caso)
gapminder_data <- gapminder %>% sheet_names() %>%
map_df(~ read_sheet(gapminder, sheet = .)) %>%