Skip to content

Instantly share code, notes, and snippets.

guidocor

Block or report user

Report or block guidocor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@guidocor
guidocor / clusters_valoracion_politicos.R
Created Apr 24, 2019
Clusters con la valoración media de los políticos. Encuesta preelectoral 2019
View clusters_valoracion_politicos.R
######################################################################
# Cluster Analysis de la valoración
######################################################################
rm(list=ls()); gc()
options(scipen=20)
if (!require("pacman")) install.packages("pacman")
pacman::p_load("tidyverse", "psych", "haven", "reshape2", "qgraph", "Rmisc", "Hmisc", "mclust", "corrplot")
# Sacamos del CIS la encuesta
@guidocor
guidocor / simpatia_analisis_Factorial.R
Created Apr 22, 2019
Análisis Factorial de la simpatía por los políticos en R
View simpatia_analisis_Factorial.R
Creados para tuitear sobre la encuesta preelectoral y hacer este tuit https://twitter.com/GuidoBCor/status/1120248040848334849
@guidocor
guidocor / plot_individual_estimates.R
Last active Jun 18, 2018
Plotting individual estimates
View plot_individual_estimates.R
if (!require("pacman")) install.packages("pacman")
pacman::p_load("ggplot2", "Rmisc")
#############################################################
# Preparing data (you can skip this and go to the plot : )
#############################################################
# Simulate some date by trial
parts = 30 # Our participants
trials = 60 # Our Trials
df=data.frame()
View ploting_stimates_in_R.R
#############################################################
## Estimating and plotting Generalized Linear Mixed Models ##
#############################################################
# This script will
# 1) Simulate some experimental data
# 2) Run a glmer with afex
# 3) Estimate predicted marginal means with emmeans
# 4) Plot estimates
View clean_and_graph_RT.R
# Snippet to call and install all libraries required with pacman package
if (!require('pacman')) install.packages('pacman'); library('pacman')
p_load(tidyverse, yarrr, trimr, lattice, doBy, Rmisc, reshape2)
# Dataset taken from trimr package. Check it out and
# don't miss this other way to do Reaction Time outlier detection
# at https://cran.r-project.org/web/packages/trimr/vignettes/trimr-vignette.html
data(exampleData)
head(exampleData)
View ploting_stimates_in_base.R
###"Plotting model estimates in base R graphics"
#There are many ways of displaying data and graphs in R,
#here I propose a base graph solution to plot estimates and confidence
#intervals using a Generalized Linear Mixed Effect Model, but this code
#could be used for other kind of models. So, we have
#a Generalized Linear Effect Model and we want to plot the
#model estimates and its confidence interval. First we install
@guidocor
guidocor / get_iqr_1_5.R
Created Sep 28, 2016
Gets the IQR and 1.5 range of the distribution of each member or of class
View get_iqr_1_5.R
iqr_1.5 <- function(df, rt, conds, FUN = function(x) {
c(iqr = IQR(x),
lower = quantile(x, c(0.25))-1.5*(quantile(x, c(0.75))-quantile(x, c(0.25))),
upper = quantile(x, c(0.75))+1.5*(quantile(x, c(0.75))-quantile(x, c(0.25))))
}){
# This function calculates the 1.5 * IQR of each participant and condition
# returns a dataframe with the columns formatted.
# Is used to detect outliers in reaction times at participant per condition level.
# Also, yo can use it with custom functions
View apa_correlation_report.R
# helper function that makes a correlation
# Computes correlation between x and y and returns a list with the
# correlation object and the text as APA states to report it
# Also, the function prints the result, you can change this behavior with silent = FALSE
# Correlation reporting in APA Style: http://my.ilstu.edu/~jhkahn/apastats.html
# Brackets of CI in APA Style: http://blog.apastyle.org/apastyle/2010/06/formatting-statistics-using-brackets.html
correlation <- function(x,y, silent = TRUE, my.method="pearson") {
View plotting_histogram_and_density.R
# Cleaning the session
rm(list=ls());gc()
# Useul function to load and install al needed packages
# we are reading it from my gist on GitHub.
source("https://raw.githubusercontent.com/guidocor/R_utils/master/install.R")
install_and_detach(c("dplyr","ggplot2", "doBy"),load= T, clean = T)
theme_set(theme_bw()) # My favourite ggplot2 theme : )
parts = 30 # Our participants
trials = 30 # Our Trials
View get_png_x_y_size.R
# -------------------------------------------------------
# READ IMAGES: Script that reads the images (png) of a folder and
# create a csv with number, size y bytes, x and y length
# -------------------------------------------------------
setwd("~/Dropbox/p1/")
source("./utils/install.R") #source("https://raw.githubusercontent.com/guidocor/R_utils/master/install.R")
install_and_detach("png",clean = F,load = T)
# my own script (install.R), but you can use
# install.packages("png"); library(png)
You can’t perform that action at this time.