Skip to content

Instantly share code, notes, and snippets.

View sillasgonzaga's full-sized avatar

Sillas Teixeira Gonzaga sillasgonzaga

View GitHub Profile
#1 Baixar série historica do dolar de 2 anos
library(quantmod)
library(xlsx)
library(plyr)
library(dplyr)
library(corrplot)
@sillasgonzaga
sillasgonzaga / pi_accuracy.R
Created July 7, 2016 01:05
Prediction intervals for forecasting models
pi_accuracy <- function(fc, yobs){
# source: http://ellisp.github.io/blog/2016/01/30/hybrid-forecasts
# checks the success of prediction intervals of an object of class
# forecast with actual values
if(length(yobs) != length(fc$mean)){
stop("yobs needs to be the same length as the forecast period.")
}
n <- length(yobs)
yobsm <- cbind(yobs, yobs)
In <- (yobsm > fc$lower & yobsm < fc$upper)
# source: http://stackoverflow.com/a/21030800/4577128
clipboard <- function(x, sep="\t", row.names=FALSE, col.names=TRUE){
con <- pipe("xclip -selection clipboard -i", open="w")
write.table(x, con, sep=sep, row.names=row.names, col.names=col.names)
close(con)
}
# projeto analise de sentimento
library(tidyr)
library(dplyr)
library(magrittr)
library(stringr)
library(lubridate)
library(ggplot2)
library(tm)
library(SnowballC)
library(wordcloud)
library(stringr)
library(magrittr)
library(lubridate)
library(glue)
library(dplyr)
library(readr)
# exemplo:
extrair_ans_UF <- function(uf, limpar_pasta_temporaria = TRUE) {
# source: https://gist.github.com/corynissen/5389426
getLongURL.curl <- function(shorturl){
# uses curl statement to get expanded url from t.co links (or any link)
# loop through until there's no location attribute... that's the long link.
newurl <- shorturl
url <- ""
while(url != newurl){
data <- system(paste0("curl -I ", newurl), intern=T)
if(sum(grepl("location: ", tolower(data))) == 0){
@sillasgonzaga
sillasgonzaga / exemplo_curso_st.R
Created October 28, 2017 18:50
Exemplo de agrupar forecasts
library(tidyverse)
library(purrr)
library(forecast)
library(lubridate)
vetor_uf <- c("RJ", "SP", "MG", "ES")
vetor_data <- seq.Date(as.Date("2010-01-01"), by = "month",
length.out = 60)
meu_tema <- function(base.size = 9, legend.text.size = 9, axis.text.size = 10, axis.title.size = 11) {
# exemplo da função lm
#ggplot(agua_agregado, aes(x = dif_pressao, y = vazao_massica_media)) +
# geom_point() + geom_smooth(method = "lm") +
@sillasgonzaga
sillasgonzaga / EmotionOfStrangerThings.R
Created November 8, 2017 01:46
Stranger Things Analysis
#Code for "A Statistical Curiosity Voyage Through the Emotion of Stranger Things"
#Article and code written by Jordan Dworkin (https://medium.com/@jordandworkin/)
###############################################################################
####### Pull script data (would need to be edited based on data source) #######
###############################################################################
library(rvest)
library(tibble)
grafico_tfidf <- function(data, n_grams = 1, remover_nomes_proprios,
agregar_por_noticia, remover_stop_words = TRUE){
data <- data %>%
unnest_tokens(palavra, corpo_noticia, token = "ngrams", n = n_grams, to_lower = FALSE)
if (agregar_por_noticia){
# remover as duplicatas dentre de uma mesma noticia
data %<>% distinct(url, palavra, .keep_all = TRUE)
}