Skip to content

Instantly share code, notes, and snippets.

View benilton's full-sized avatar

Benilton Carvalho benilton

  • Universidade Estadual de Campinas (UNICAMP)
  • Campinas
  • X @benilton
View GitHub Profile
@benilton
benilton / CMR.R
Created July 17, 2011 23:06
Codigo minimo reproduzivel em R
## Este exemplo provê um código em R que outros usuários podem reproduzir
## para facilitar a solução de problemas observados.
##
## Na R-br em: http://r-br.2285057.n4.nabble.com/R-br-Produzindo-um-Codigo-Minimo-Reproduzivel-CMR-td3674188.html
#################################################################
## PASSO 1: Carregue os pacotes necessários no início do código
#################################################################
library(splines)
@benilton
benilton / sobreposicaoPolygon.R
Created August 15, 2011 10:55
Sobreposição de Gráficos Usando polygon()
## Por Benilton Carvalho
##
## Determinando os parâmetros da Normal
media <- 170
stder <- 8
## Criando o grid no qual deseja-se visualizar a densidade
x <- seq(media-3*stder, media+3*stder, .01)
## Determinando a densidade em cada ponto do grid
@benilton
benilton / oligoInstall.R
Created August 21, 2011 22:32
Installing the oligo package
## Installing the oligo package
## Requires biocLite()
source("http://www.bioconductor.org/biocLite.R")
biocLite("oligo")
@benilton
benilton / problema.r
Created September 23, 2011 15:32
Explicacao do problema....
## funcao initial
equantileByCounts <- function(x, counts, qs){
tot <- sum(counts)
i <- order(x)
x <- x[i]
counts <- counts[i]
partial <- cumsum(counts)
qsObs <- qs*tot
start <- floor(qsObs)
end <- ceiling(qsObs)
## Conjunto de dados
x = structure(list(pop = c(23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L), ind = c(12L,
12L, 14L, 14L, 18L, 18L, 20L, 20L, 21L, 21L, 22L, 22L, 24L, 24L,
25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 31L, 31L, 32L,
32L, 33L, 33L, 34L, 34L, 36L, 36L, 42L, 42L, 49L, 49L, 51L, 52L,
52L, 58L, 58L, 59L, 59L), morph = c("long", "long", "long", "long",
"long", "long", "long", "long", "long", "long", "semi-M_AL",
@benilton
benilton / voltaCoKri2.R
Created May 31, 2012 23:58
Modifying the source of volta.cokri (by PJ's grp) to use parallel computing and memory more efficiently...
volta.cokri2 <- function(mat.cokri, num.simu, retorna.tudo=FALSE, int.conf=0.95){
## Author: Wagner Bonat / Ana Beatriz Martins / Paulo Justiniano
## Modified for parallel and better use of RAM by: Benilton Carvalho
require(parallel)
nlinhas <- dim(mat.cokri[[1]])[1]
f <- function(i){
g <- mvrnorm(n=1, mat.cokri[[1]], mat.cokri[[2]])
seq1 <- seq(1, nlinhas, by=2)
gerado <- data.frame(g[seq1], g[seq1+1L])
@benilton
benilton / CreateHuGeneAnnot.R
Created July 21, 2012 00:50
Create HuGene Annotation with pdInfoBuilder
library(pdInfoBuilder)
seed <- new("AffySTPDInfoPkgSeed",
version="3.6.0",
license="Artistic-2.0",
pgfFile=dir(patt=".pgf$"),
clfFile=dir(patt=".clf$"),
probeFile=dir(patt="probeset.csv$"),
transFile=dir(patt="transcript.csv$"),
coreMps=dir(patt="core.mps$"),
fullMps=dir(patt="full.mps$"),
@benilton
benilton / emMisturaFinita.R
Created May 30, 2017 13:51
Algoritmo EM - Exemplo em Mistura Finita
## Gerando dados
set.seed(1)
y1 = rnorm(20, 2.5, 1.25)
y2 = rnorm(20, 5, 1.25)
Y = c(y1, y2)
data(faithful)
plot(faithful$waiting, faithful$eruptions)
@benilton
benilton / emMisturaRegressoes.R
Created May 30, 2017 13:53
Algoritmo EM - Mistura de Regressões
## Gerando dados
set.seed(1)
y1 = rnorm(20, 2.5, 1.25)
y2 = rnorm(20, 5, 1.25)
Y = c(y1, y2)
##
data(faithful)
plot(faithful$waiting, faithful$eruptions)
data(cars)
fit = lm(dist ~ speed, data=cars)
summary(fit)
system.time({
nBoot = 10000
coefs = rep(NA, nBoot)
for (j in 1:nBoot){
i = sample(nrow(cars), replace = TRUE)
fitBoot = lm(dist ~ speed, data=cars[i,])