Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simcaq_statistics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team DB
Simcaq_statistics
Commits
a3b9f7cf
Commit
a3b9f7cf
authored
1 year ago
by
mgy20
Browse files
Options
Downloads
Patches
Plain Diff
Adicionado ad sem hist
parent
f884ca99
Branches
Branches containing commit
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Testes_R/teste_ad.r
+136
-0
136 additions, 0 deletions
Testes_R/teste_ad.r
with
136 additions
and
0 deletions
Testes_R/teste_ad.r
0 → 100644
+
136
−
0
View file @
a3b9f7cf
#!/usr/bin/env Rscript
# Function to remove outliers using the IQR method
remove_outliers
<-
function
(
data
)
{
# Calculate the interquartile range (IQR)
Q1
<-
quantile
(
data
,
0.25
)
Q3
<-
quantile
(
data
,
0.75
)
IQR
<-
Q3
-
Q1
# Define the lower and upper bounds
lower_bound
<-
Q1
-
1.5
*
IQR
upper_bound
<-
Q3
+
1.5
*
IQR
# Remove outliers
cleaned_data
<-
data
[
data
>=
lower_bound
&
data
<=
upper_bound
]
# Return the cleaned data
return
(
cleaned_data
)
}
# MAIN ==========================================
# Carrega CSV
options
(
warn
=
-1
)
library
(
kSamples
)
df
=
read.csv
(
"../dados/escola_integers.csv"
,
sep
=
"|"
)
#head(df)
# Colunas do csv de saida
colunas
=
c
(
"coluna1"
,
"ano_coluna1"
,
"coluna2"
,
"ano_coluna2"
,
"tamanho_amostra"
,
"estatistica_ad"
,
"p_valor"
)
output_df
=
data.frame
(
matrix
(
ncol
=
length
(
colunas
),
nrow
=
0
))
# Remove ANO_CENSO das iteracoes
atributos
=
names
(
df
)
atributos
=
atributos
[
atributos
!=
"ANO_CENSO"
]
# Separa os anos em amostras
ANO
<-
df
[
"ANO_CENSO"
]
for
(
ano
in
sort
(
unique
(
df
$
ANO_CENSO
))){
for
(
col1
in
atributos
)
{
for
(
col2
in
atributos
)
{
# Amostra de um ano
X
<-
df
[
col1
]
data1
<-
X
[
ANO
==
ano
]
# Amostra do ano seguinte
Y
<-
df
[
col2
]
data2
<-
Y
[
ANO
==
ano
+1
]
# Remove zeros
data1
<-
data1
[
data1
!=
0
]
data2
<-
data2
[
data2
!=
0
]
# Remove NaN, outliers e ordena
data1
<-
remove_outliers
(
na.omit
(
data1
))
data2
<-
remove_outliers
(
na.omit
(
data2
))
# Pula casos em que não há dados nas amostras
if
(
length
(
data1
)
==
0
||
length
(
data2
)
==
0
){
next
}
# Teste AD
resultado
=
ad.test
(
list
(
data1
,
data2
))
estatistica
=
(
resultado
$
ad
[
1
,
1
]
+
resultado
$
ad
[
2
,
1
])
/
2
p_valor
=
(
resultado
$
ad
[
1
,
3
]
+
resultado
$
ad
[
2
,
3
])
/
2
# Concatena resultados no dataframe
nova_linha
=
c
(
col1
,
ano
,
col2
,
ano
+1
,
length
(
data1
),
estatistica
,
p_valor
)
output_df
=
rbind
(
output_df
,
nova_linha
)
}
}
}
output_csv
=
"../R_resultados/Sem_histograma/AD_subsequente.csv"
colnames
(
output_df
)
<-
colunas
write.csv
(
output_df
,
file
=
output_csv
,
row.names
=
FALSE
)
# ACUMULADO =====================================
# Colunas do csv de saida
colunas
=
c
(
"coluna1"
,
"ano_coluna1"
,
"coluna2"
,
"ano_coluna2"
,
"tamanho_amostra"
,
"estatistica_ad"
,
"p_valor"
)
output_df
=
data.frame
(
matrix
(
ncol
=
length
(
colunas
),
nrow
=
0
))
ano_start
=
min
(
df
$
ANO_CENSO
)
# Remove ANO_CENSO das iteracoes
atributos
=
names
(
df
)
atributos
=
atributos
[
atributos
!=
"ANO_CENSO"
]
# Separa os anos em amostras
ANO_COLUMN
<-
df
[
"ANO_CENSO"
]
for
(
ano
in
sort
(
unique
(
df
$
ANO_CENSO
))){
for
(
col1
in
atributos
)
{
for
(
col2
in
atributos
)
{
# Amostra acumulada dos anos
X
<-
df
[
col1
]
data1
<-
X
[
ANO_COLUMN
>=
ano_start
&
ANO_COLUMN
<=
ano
]
# Amostra do ano seguinte
Y
<-
df
[
col2
]
data2
<-
Y
[
ANO_COLUMN
==
ano
+1
]
# Remove zeros
data1
<-
data1
[
data1
!=
0
]
data2
<-
data2
[
data2
!=
0
]
# Remove NaN, outliers e ordena
data1
<-
remove_outliers
(
na.omit
(
data1
))
data2
<-
remove_outliers
(
na.omit
(
data2
))
# Pula casos em que não há dados nas amostras
if
(
length
(
data1
)
==
0
||
length
(
data2
)
==
0
){
next
}
# Teste AD
resultado
=
ad.test
(
list
(
data1
,
data2
))
estatistica
=
(
resultado
$
ad
[
1
,
1
]
+
resultado
$
ad
[
2
,
1
])
/
2
p_valor
=
(
resultado
$
ad
[
1
,
3
]
+
resultado
$
ad
[
2
,
3
])
/
2
# Concatena resultados no dataframe
nova_linha
=
c
(
col1
,
ano
,
col2
,
ano
+1
,
length
(
data1
),
estatistica
,
p_valor
)
output_df
=
rbind
(
output_df
,
nova_linha
)
}
}
}
output_csv
=
"../R_resultados/Sem_histograma/AD_acumulado.csv"
colnames
(
output_df
)
<-
colunas
write.csv
(
output_df
,
file
=
output_csv
,
row.names
=
FALSE
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment