This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Teste de Bartlett - a hipótese nula da matriz de correlação ser uma matriz identidade ( $| R | = 1$ ), | |
#isto é, avalia se os componentes fora da diagonal principal são zero. | |
#O resultado significativo indica que existem algumas relações entre as variáveis. | |
Bartlett.sphericity.test <- function(x) | |
{ | |
method <- "Teste de esfericidade de Bartlett" | |
data.name <- deparse(substitute(x)) | |
x <- subset(x, complete.cases(x)) # Omitindo valores faltantes | |
n <- nrow(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rJava) | |
library(RWeka) | |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
#+ ngrams com RWeka: + | |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
Tokenizer <- function(x) NGramTokenizer(x, Weka_control(min = ngrams, max = ngrams)) | |
myDTM = TermDocumentMatrix(myCorpus,control = list(tokenize = Tokenizer)) | |
# ----------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trecho da funcao obtida em : | |
# http://www.sthda.com/english/wiki/word-cloud-generator-in-r-one-killer-function-to-do-everything-you-need | |
# Download e analise de webpage | |
html_to_text<-function(url){ | |
library(RCurl) | |
library(XML) | |
# download html | |
html.doc <- getURL(url) | |
#convert to plain text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Função realiza o qqplot com "envelope" | |
#Envelope | |
envelope<-function(x){ | |
n <- length(x) | |
nsim <- 100 # Número de simulações | |
conf <- 0.95 # Coef. de confiança | |
# Dados simulados ~ normal | |
dadossim <- matrix(rnorm(n*nsim, mean = mean(x), sd = sd(x)), nrow = n) | |
dadossim <- apply(dadossim,2,sort) | |
# Limites da banda e média |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Funcao para correlacoes | |
my_fn <- function(data, mapping, method="lm", ...){ | |
p <- ggplot(data = data, mapping = mapping) + | |
geom_point() + | |
geom_smooth(method=method, ...) | |
p | |
} | |
data(tips, package = "reshape") | |
# Uso: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Como utilizar a funcao wordcloud_sentiment(): | |
#----------------.-------------------------------------------------------------------------------------------------.---------------------- | |
# Argumento | Definicao | Default | |
#----------------|------------------------------------------------------------------------------------------------------------------------ | |
# x | Coluna com textos, ou url (ver type) | | |
#----------------|------------------------------------------------------------------------------------------------------------------------ | |
# type | Tipo de arquivo para produzir a nuvem | | |
# |- url: Endereço da qual deseja-se fazer a nuvem | | |
# |- text: Coluna com textos (cada linha representa um comentario) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fonte: http://www.leg.ufpr.br/Rpira/Rpira/node11.html | |
ic.m <- function(x, conf = 0.95){ | |
n <- length(x) | |
media <- mean(x) | |
variancia <- var(x) | |
quantis <- qt(c((1-conf)/2, 1 - (1-conf)/2), df = n-1) | |
ic <- media + quantis * sqrt(variancia/n) | |
return(ic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
# define %notin% function | |
"%!in%" <- function(x,y)!("%in%"(x,y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages = c('<package1>', '<package2>') | |
for (package in packages) { | |
if (!require(package, character.only=T, quietly=T)) { | |
install.packages(package) | |
library(package, character.only=T) | |
} | |
} | |
# Ref: https://stackoverflow.com/questions/5595512/what-is-the-difference-between-require-and-library?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
values <- list(c("<b>affairs</b>", "gender", "age","yearsmarried","children","religiousness","education","occupation","rating"), | |
c("Quantas vezes envolvido em caso extraconjugal no último ano", | |
"Sexo", | |
"Idade", | |
"Número de anos casado", | |
"Crianças", | |
"Como religioso", | |
"Nível de educação", | |
"Ocupação", | |
"Como classifica o casamento"), |
OlderNewer