Skip to content

Instantly share code, notes, and snippets.

View eliardocosta's full-sized avatar
🎯
Focusing

Eliardo Costa eliardocosta

🎯
Focusing
View GitHub Profile
@eliardocosta
eliardocosta / README.md
Last active July 31, 2017 18:41
The R codes to implement the algorithms and figures in Costa, Lopes & Singer (2015).

Description

These are the R codes to implement the algorithms and figures in Costa, Lopes & Singer (2015).

Reference

License

The MIT License (MIT)
@eliardocosta
eliardocosta / README.md
Last active August 2, 2017 20:30
The R codes to implement the algorithms and figures in Costa, Lopes & Singer (2016).

Description

These are the R codes to implement the algorithms and figures in Costa, Lopes & Singer (2016).

Reference

License

The MIT License (MIT)
# benford_file.R
#
# Copyright (c) 2017 Eliardo Costa
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the BSD Zero Clause License as published by
# Rob Landley. See http://spdx.org/licenses/0BSD.html for more details.
benford_file <- function(vecdata, filename, source.url, ds) {
cd <- getwd()
@eliardocosta
eliardocosta / MITLicenseRStudio.md
Created July 28, 2017 16:11
Adding a snippet to insert MIT License in RStudio scripts.

1- Go to Tools -> Global Options -> Code -> Snippets -> Edit Snippets.
2- Then paste the following code:

snippet mit
	`r paste('#  script.R')`
	`r paste('#')`
	`r paste('#  The MIT License (MIT)')`
	`r paste('#')`
	`r paste('#  Copyright (c)', format(Sys.time(), "%Y"), '<Your name>')`
	`r paste('#')`
@eliardocosta
eliardocosta / 0BSDLicenseRStudio.md
Last active July 28, 2017 20:07
Adding a snippet to insert 0BSD License header in RStudio scripts.

1- Go to Tools -> Global Options -> Code -> Snippets -> Edit Snippets.
2- Then paste the following code:

snippet 0bsd
	`r paste('#  script.R')`
	`r paste('#')`
	`r paste('#  Copyright (c)', format(Sys.time(), "%Y"), '<Your name>')`
	`r paste('#')`
	`r paste('#  This program is free software; you can redistribute it and/or modify')`
	`r paste('# it under the terms of the BSD Zero Clause License as published by')`
@eliardocosta
eliardocosta / main.R
Last active April 21, 2019 04:17
Minimal templates for Geany.
{fileheader}
main <- function() {
return(cat())
}
if(interactive()) main()
@eliardocosta
eliardocosta / pi_por_simulacao.R
Last active June 18, 2021 13:47
Obtendo a constante Pi por simulação de pontos no (0,1)x(0,1) e calculando a proporção de pontos dentro da circunferência.
r <- 0.5 # raio da circunferencia
n <- 1E5
x <- runif(n)
y <- runif(n)
pdentro <- numeric(n)
for (i in seq_len(n)) { # contando os pontos dentro da circunferencia
pdentro[i] <- ifelse((x[i] - 0.5)^2 + (y[i] - 0.5)^2 <= r^2, 1, 0)
}
@eliardocosta
eliardocosta / exemplo3clusters.R
Last active April 21, 2019 03:57
Blocked gibbs sampling for Dirichlet process.
n <- 50
w <- 1
set.seed(161017)
lam <- sample(c(5, 25, 50), n, replace = TRUE, prob = c(0.35, 0.3, 0.35)) # 3 clusters!
x <- rpois(n, w*lam)
hist(x, prob = TRUE, breaks = 15)
source("https://gist.githubusercontent.com/eliardocosta/7c350eece9f09a7caa0f48852621063c/raw/dd6eae6d9bb3101bdeeff0d9d087db91f9d7e74d/ppostPoiDP.R")
foo <- ppostPoiDP(x = x, w = w, phi = sqrt(mean(x)/var(x)), lam0 = mean(x), alpha = 1, nburn = 500, nsam = 1E3)
hist(foo$nclu) # histograma num. de clusters por iteracao
plot(foo$lam, foo$fdist) # distribuicao acumulada a posteriori
@eliardocosta
eliardocosta / README.md
Last active December 2, 2020 19:53
The R codes to implement the illustrative example in Costa, Paulino & Singer (2020).

Description

These are the R codes to implement the illustrative example in Costa, Paulino & Singer (2020, submitted).

License

The MIT License (MIT)

Copyright (c) 2020 Eliardo G. Costa, Carlos Daniel Paulino & Julio M. Singer

Permission is hereby granted, free of charge, to any person obtaining a copy of
# Adaptacao da funcao 'mwar.ani' do pacote 'animation' do R para
# ilustrar o conceito de media movel para k observacoes consecutivas
mm.ani = function(x, k = 7, mat = matrix(1:2, 2),
widths = rep(1, ncol(mat)),
heights = rep(1, nrow(mat)), lty.rect = 2, ...) {
nmax = ani.options('nmax')
n = length(x)
if (k > n)
stop('A largura da janela k deve ser menor que o tamanho de x!')