Sugestão de referência:
GIVISIEZ, Gustavo Henrique Naves. Descrevendo os dados [R Markdown Document]. . Campos dos Goytacazes (RJ): RPubs. Disponível em: https://rpubs.com/ghnaves/Descrevendo. Acesso em: 26 abr. 2022. , 2022
Os exercícos a seguir foram adaptados dos capítulos 1 a 8 do livro de autoria de Joseph Schmuller (Schmuller and Batista 2019).
As bases de dados usadas nas atividades são os seguintes:
Dados da população mundial. Disponível na Gapminder Foundation (Gapminder Foundation 2020). Os dados podem ser baixados nesse link
Dados das cotas do Rio Paraíba do Sul, estação fluviométrica da Ponte Municipal de Campos (Codigo 5897400). Disponível no HidroWeb(ANA 2022). Os dados podem ser baixados nesse link
Dados históricos e projetados da população das cidades do mundo com população maior que 300 mil habitantes em 2018. Disponível no site de Dinâmica Populacional do Departamento de Assuntos Econômicos e Sociais das Nações Unidas (United Nations, Departament of Economic and Social Affairs 2018). Os dados podem ser baixados nesse link
Dados sobre o uso de bicicletas em londres de 2015 a 2017 (Khandelwal 2022). Disponível no Kaggle (London bike sharing dataset). Os dados podem ser baixados nesse link
Dados do QI de 758 indivíduos (Griliches 1976; Chansta (Confidential User) 2021). Disponível no Kaggle (06ModelandPrediction). Os dados podem ser baixados nesse link
Inicialmente, criem um novo projeto, um novo script e salvem os arquivos acima referenciados na pasta do projeto.
Gapminder<-readRDS('gapminder.rds')
CpGoy<-readRDS('cpgoy.rds')
Cities_Pop <- readRDS('Cities_pop.RDS')
bike_lon <- readRDS('london_merged.RDS')
IQ<-readRDS('IQ.rds')View(Gapminder)
View(CpGoy)
View(Cities_Pop)
View(bike_lon)class
summary, str e headclass(CpGoy)## [1] "tbl_df" "tbl" "data.frame"
summary(CpGoy)## EstacaoCodigo Data Cota ano
## Min. :58974000 Min. :1930-01-01 Min. : 439.0 Min. :1930
## 1st Qu.:58974000 1st Qu.:1952-07-01 1st Qu.: 604.0 1st Qu.:1952
## Median :58974000 Median :1974-12-31 Median : 660.0 Median :1974
## Mean :58974000 Mean :1974-12-31 Mean : 674.6 Mean :1974
## 3rd Qu.:58974000 3rd Qu.:1997-07-01 3rd Qu.: 730.0 3rd Qu.:1997
## Max. :58974000 Max. :2019-12-31 Max. :1174.0 Max. :2019
##
## decada
## 1940 : 3653
## 1960 : 3653
## 1980 : 3653
## 2000 : 3653
## 1930 : 3652
## 1950 : 3652
## (Other):10956
str(CpGoy)## Classes 'tbl_df', 'tbl' and 'data.frame': 32872 obs. of 5 variables:
## $ EstacaoCodigo: num 5.9e+07 5.9e+07 5.9e+07 5.9e+07 5.9e+07 ...
## $ Data : Date, format: "1930-01-01" "1930-02-01" ...
## $ Cota : num 826 780 876 732 710 698 644 648 638 658 ...
## $ ano : num 1930 1930 1930 1930 1930 1930 1930 1930 1930 1930 ...
## $ decada : Factor w/ 9 levels "1930","1940",..: 1 1 1 1 1 1 1 1 1 1 ...
head(CpGoy)| EstacaoCodigo | Data | Cota | ano | decada |
|---|---|---|---|---|
| 58974000 | 1930-01-01 | 826 | 1930 | 1930 |
| 58974000 | 1930-02-01 | 780 | 1930 | 1930 |
| 58974000 | 1930-03-01 | 876 | 1930 | 1930 |
| 58974000 | 1930-04-01 | 732 | 1930 | 1930 |
| 58974000 | 1930-05-01 | 710 | 1930 | 1930 |
| 58974000 | 1930-06-01 | 698 | 1930 | 1930 |
hist(CpGoy$Cota,col='lightblue')library(ggplot2)
ggplot(CpGoy,aes(x=Cota))+
geom_histogram(binwidth=25,color='black',fill='#5C88DAB2')+
labs(x='Cotas (em metros)',y='Freq',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
theme_bw()Gap2020<-Gapminder[Gapminder$time==2020,]
head(Gap2020)| geo | name | four_regions | eight_regions | six_regions | members_oecd_g77 | Lat | Long | Dt_UNMember | WB_reg | WB_income2017 | time | pop | ipp | gdp | tfr | le | cm | co2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| afg | Afghanistan | Asia | Ásia Ocidental | Sul da Ásia | g77 | 33.00000 | 66.00000 | 1946-11-19 | South Asia | Low income | 2020 | 38928341 | 1800 | 70068416143 | 4.04 | 64.41 | 58.08 | NA |
| alb | Albania | Europa | Leste Europeu | Europa Central e Ásia Ocidental | others | 41.00000 | 20.00000 | 1955-12-14 | Europe & Central Asia | Upper middle income | 2020 | 2877800 | 13225 | 38059435150 | 1.70 | 78.58 | 8.52 | NA |
| dza | Algeria | África | África do Norte | Oriente Médio e Norte da África | g77 | 28.00000 | 3.00000 | 1962-10-08 | Middle East & North Africa | Upper middle income | 2020 | 43851043 | 14040 | 615652019591 | 2.54 | 78.31 | 22.18 | NA |
| and | Andorra | Europa | Europa Ocidental | Europa Central e Ásia Ocidental | others | 42.50779 | 1.52109 | 1993-07-28 | Europe & Central Asia | High income | 2020 | 77265 | 55047 | 4253206455 | NA | NA | 2.85 | NA |
| ago | Angola | África | África Subsaariana | África Subsaariana | g77 | -12.50000 | 18.50000 | 1976-12-01 | Sub-Saharan Africa | Lower middle income | 2020 | 32866268 | 5444 | 178938060987 | 5.41 | 65.36 | 72.29 | NA |
| atg | Antigua and Barbuda | Américas | América do Norte | América | g77 | 17.05000 | -61.80000 | 1981-11-11 | Latin America & Caribbean | High income | 2020 | 97928 | 25007 | 2448889606 | 2.01 | 77.41 | 6.09 | NA |
library(dplyr)
Gap2020 <- Gapminder %>%
filter(time == 2020) %>%
group_by(six_regions) %>%
summarise(pop=sum(pop))
barplot(Gap2020$pop ~ Gap2020$six_regions,
xlab = "Regiões",
ylab = "População Total",
col = c("#CC0C00B2","#5C88DAB2","#84BD00B2","#FFCD00B2","#7C878EB2","#00B5E2B2"),
)library(ggplot2)
Gap <- Gapminder %>%
filter(time %in% seq(1950,2020,10)) %>%
group_by(six_regions,time) %>%
summarise(pop=sum(pop))%>%
ungroup()
ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar()ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar()+
coord_flip()ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_dodge())ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_fill())library(scales)
ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_y_continuous(labels=label_number())ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_y_continuous(labels=label_comma())ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_y_continuous(labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-9))ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_fill())+
labs(title='População por região mundial',x='Ano',y='%',subtitle = '1950 a 2020')library(RColorBrewer)
library(ggsci)
ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_startrek()+
labs(title='População por região mundial',
x='Ano',
y='População (milhões de hab.)',
subtitle = '1950 a 2020',
fill='Regiões do Mundo')ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(name='População (milhões de hab.)',
labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-6),)+
scale_x_continuous(name='Ano',
breaks = seq(1950,2020,10),labels=seq(1950,2020,10))+
labs(title='População por região mundial',
subtitle = '1950 a 2020')ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(name='População (milhões de hab.)',
labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-6),)+
scale_x_continuous(name='Ano',
breaks = seq(1950,2020,10),labels=seq(1950,2020,10))+
labs(title='População por região mundial',
subtitle = '1950 a 2020')+
theme_minimal()ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(name='População (milhões de hab.)',
labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-6),)+
scale_x_continuous(name='Ano',
breaks = seq(1950,2020,10),labels=seq(1950,2020,10))+
labs(title='População por região mundial',
subtitle = '1950 a 2020')+
theme_dark()library(ggthemes)
ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-6),
name='População (milhões de hab.)')+
scale_x_continuous(name='Ano',breaks = seq(1950,2020,10),labels=seq(1950,2020,10))+
labs(title='População por região mundial',
subtitle = '1950 a 2020')+
theme_economist()ggplot(data=Gap,aes(x=time,weight=pop,fill=six_regions))+
geom_bar(position=position_stack())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^-6),
name='População (milhões de hab.)')+
scale_x_continuous(name='Ano',breaks = seq(1950,2020,10),labels=seq(1950,2020,10))+
labs(title='População por região mundial',
subtitle = '1950 a 2020')+
theme_fivethirtyeight()Cities <- Cities_Pop %>%
group_by(six_regions,time) %>%
mutate(grande=if_else(Pop>=1000,1,0))%>%
summarise(Pop=sum(Pop),n=sum(grande))%>%
ungroup()
ggplot(data=Cities,aes(x=time,weight=n,fill=six_regions))+
geom_bar()+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^0),
name='Total')+
scale_x_continuous(name='Ano',breaks = seq(1950,2035,10),labels=seq(1950,2035,10))+
labs(title='Total de cidades com mais de um milhão de habitantes',
subtitle = 'Por região, de 1950 a 2035')+
theme_minimal()ggplot(data=Cities,aes(x=time,weight=n,fill=six_regions))+
geom_bar(position=position_fill())+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
scale_y_continuous(labels=label_comma(big.mark = '.',decimal.mark = ',',scale=10^0),
name='Total')+
scale_x_continuous(name='Ano',breaks = seq(1950,2035,10),labels=seq(1950,2035,10))+
labs(title='Total de cidades com mais de um milhão de habitantes',
subtitle = 'Por região, de 1950 a 2035')+
theme_minimal()Cities2<-Cities %>%
filter(time==2035)
ggplot(data=Cities2,aes(x='',y=n,fill=six_regions))+
geom_bar(stat='identity',width=1)+
coord_polar("y",start=0)+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
labs(title='Total de cidades com mais de um milhão de habitantes',
subtitle = 'Por região, 2035')+
theme_minimal()ggplot(data=Cities2,aes(x='',y=n,fill=six_regions))+
geom_bar(stat='identity',width=1)+
coord_polar("y",start=0)+
scale_fill_brewer(name='Regiões do Mundo',
palette='Set2')+
labs(title='Total de cidades com mais de um milhão de habitantes',
subtitle = 'Por região, 2035')+
theme_minimal()+
theme_void()
## Gráfico de dispersão
Gapminder_2020<- Gapminder %>%
filter(time==2020)
ggplot(data=Gapminder_2020, aes(x=ipp,y=le))+
geom_point()## Warning: Removed 11 rows containing missing values (geom_point).
ggplot(data=Gapminder_2020, aes(x=ipp,y=le))+
geom_point()+
scale_x_log10(labels=comma)## Warning: Removed 11 rows containing missing values (geom_point).
Gapminder_1950_2020<- Gapminder %>%
filter(time==2020|time==1950)
ggplot(data=Gapminder_1950_2020, aes(x=ipp,y=le,size=pop,color=eight_regions))+
geom_point()+
facet_wrap(.~time)+
scale_x_log10(labels=comma)## Warning: Removed 22 rows containing missing values (geom_point).
ggplot(data=Gapminder_1950_2020,aes(x=ipp,y=le,color=six_regions))+
geom_point()+
scale_x_log10(labels=comma)+
labs(x='Log(Renda Percapita em US$)', y = 'Espeança de vida ao nascer')## Warning: Removed 22 rows containing missing values (geom_point).
ggplot(data=Gapminder_1950_2020,aes(x=ipp,y=le,color=six_regions))+
geom_point()+
scale_x_log10(labels=comma)+
labs(x='Log(Renda Percapita em US$)', y = 'Espeança de vida ao nascer')+
facet_wrap(~time)## Warning: Removed 22 rows containing missing values (geom_point).
Gapminder_1860a2020<- Gapminder %>%
filter(time %in% seq(1860,2020,20))
ggplot(data=Gapminder_1860a2020,aes(x=ipp,y=le,color=six_regions))+
geom_point()+
scale_x_log10(labels=comma)+
labs(x='Log(Renda Percapita em US$)', y = 'Espeança de vida ao nascer')+
facet_wrap(~time)## Warning: Removed 93 rows containing missing values (geom_point).
Gapminder_1860a2020<- Gapminder %>%
filter(time %in% seq(1860,2020,20))
ggplot(data=Gapminder_1860a2020,aes(y=tfr,x=le,color=six_regions))+
geom_point()+
scale_x_continuous(labels=comma)+
labs(x='Esperança de vida', y = 'Taxa de Fecundidade Total')+
facet_wrap(~time)## Warning: Removed 99 rows containing missing values (geom_point).
ggplot(CpGoy,aes(x=Cota))+
geom_histogram(binwidth=25,color='black',fill='#5C88DAB2')+
labs(x='Cotas (metros)',y='Freq',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
scale_x_continuous(labels=label_comma(scale=10^-2,accuracy =1))+
facet_wrap(~decada)+
theme_bw()1040: Cota de transbordamento
840: “O estacionamento do cais da Lapa já começou a ser tomado pelas águas” Fonte: Observatório dos desastres ambientais (2021)
Na usina hidrelétrica da Light, a jusante de Santa Cecília (no município de Barra do Piraí), é feita a transposição, quando o Paraíba do Sul cede mais de 60% de suas águas para o rio Guandu através das canalizações forçadas das usinas. O Sistema Light foi construído em 1952 e os rios Guandu, Ribeirão da Lages e a transposição do rio Paraíba do Sul abastecem 80% das necessidades da população da Região Metropolitana do Rio de Janeiro. [Fonte: Diniz (2014)] (https://www.ecodebate.com.br/2014/11/14/nova-transposicao-do-rio-paraiba-do-sul-artigo-de-jose-eustaquio-diniz-alves/)
ggplot(CpGoy,aes(y=Cota,x=decada))+
geom_boxplot(color='black',alpha=0.3,aes(fill=decada))+
labs(y='Cotas (metros)',x='Década',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
scale_y_continuous(labels=label_comma(scale=10^-2,accuracy =1))ggplot(CpGoy,aes(y=Cota,x=decada))+
geom_violin(color='black',alpha=0.3,aes(fill=decada))+
labs(y='Cotas (metros)',x='Década',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
scale_y_continuous(labels=label_comma(scale=10^-2,accuracy =1))+
geom_hline(yintercept=1040, color = "grey30")+
geom_hline(yintercept=840, color = "grey70")ggplot(CpGoy,aes(y=Cota,x=decada))+
geom_violin(color='black',alpha=0.3,aes(fill=decada))+
geom_boxplot(width=0.1, color="grey",fill='#5C88DAB2')+
labs(y='Cotas (metros)',x='Década',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
scale_y_continuous(labels=label_comma(scale=10^-2,accuracy =1))Gap.subset <- Gapminder %>%
filter(time==2020)%>%
subset(select=c(le,tfr,ipp))
library(GGally)
ggpairs(Gap.subset)Gap.subset <- Gapminder %>%
filter(time==1850)%>%
subset(select=c(le,tfr,ipp,four_regions))
ggpairs(Gap.subset,title='1850')Gap.subset <- Gapminder %>%
filter(time==2020)%>%
subset(select=c(le,tfr,ipp,four_regions))
ggpairs(Gap.subset,title='2020')mean(CpGoy$Cota)## [1] 674.6346
mean(Gapminder$ipp)## [1] NA
mean(Gapminder$ipp,na.rm=T)## [1] 6486.043
mean(Cities_Pop$Pop)## [1] 845.5724
temp<-CpGoy %>%
filter(decada=='2000')
mean(temp$Cota)## [1] 632.7044
temp<-CpGoy %>%
filter(decada=='1930')
mean(temp$Cota)## [1] 732.0835
temp<-CpGoy %>%
filter(decada=='2000')
mean(temp$Cota,trim=0.05)## [1] 623.8872
temp<-CpGoy %>%
filter(decada=='1930')
mean(temp$Cota,trim=0.05)## [1] 725.3455
Util para média de taxas de crescimento.
temp<-CpGoy %>%
filter(decada=='2000')%>%
mutate(taxa=1+(Cota-lag(Cota))/lag(Cota))
m.geom <- prod(temp$taxa,na.rm = T )^(1/length(temp$taxa))
m.geom## [1] 1.000076
Util para média de velocidades.
temp<-c(75,55,80,90,99,110,105)
m.harm <- 1/(mean(1/temp))
m.harm## [1] 83.49038
library(modeest)
temp<-CpGoy %>%
filter(decada=='2000')
mfv(temp$Cota)## [1] 576
temp<-CpGoy %>%
filter(decada=='2000' & Cota==576)sd(CpGoy$Cota)## [1] 106.2507
sd(Gapminder$ipp)## [1] NA
sd(Gapminder$ipp,na.rm=T)## [1] 13451.96
sd(Cities_Pop$Pop)## [1] 1966.964
var(CpGoy$Cota)## [1] 11289.22
var(Gapminder$ipp)## [1] NA
var(Gapminder$ipp,na.rm=T)## [1] 180955199
var(Cities_Pop$Pop)## [1] 3868946
Gap_oecd<-Gapminder %>%
filter(time==2000 & members_oecd_g77=='oecd')
Gap_g77<-Gapminder %>%
filter(time==2000 & members_oecd_g77=='g77')
sd(Gap_oecd$ipp,na.rm = T)## [1] 14064.26
sd(Gap_g77$ipp,na.rm = T)## [1] 17216.96
zscale(Gap_oecd$ipp)[1:6]## [1] 0.09954547 0.34491920 0.22724504 0.25177530 -0.91003483 0.59335032
rank(Gap_oecd$ipp)## [1] 17 23 21 22 7 26 15 14 19 8 5 16 24 18 13 6 30 4 25 10 29 2 9 3 11
## [26] 20 28 1 12 27
rank(-Gap_oecd$ipp)## [1] 14 8 10 9 24 5 16 17 12 23 26 15 7 13 18 25 1 27 6 21 2 29 22 28 20
## [26] 11 3 30 19 4
rank(Gap_g77$ipp)## [1] 5.0 100.0 60.0 119.0 113.0 122.0 125.0 29.0 114.0 83.0 28.0 57.0
## [13] 65.0 79.0 104.0 107.0 128.0 14.0 6.0 18.0 42.0 61.0 9.0 12.0
## [25] 111.0 59.0 93.0 38.0 1.5 69.0 97.0 50.0 71.0 35.0 91.0 92.0
## [37] 85.0 86.0 75.0 106.0 40.0 4.0 82.0 116.0 21.0 36.0 95.0 77.0
## [49] 23.0 19.0 68.0 30.0 54.0 45.0 76.0 110.0 108.0 89.0 84.0 33.0
## [61] 26.0 127.0 41.0 101.0 27.0 17.0 120.0 20.0 10.0 115.0 99.0 22.0
## [73] 49.0 47.0 105.0 52.0 70.0 66.0 1.5 16.0 81.0 24.0 56.0 7.0
## [85] 51.0 124.0 55.0 102.0 44.0 90.0 80.0 63.0 130.0 8.0 121.0 103.0
## [97] 87.0 64.0 32.0 123.0 39.0 118.0 11.0 126.0 31.0 3.0 96.0 74.0
## [109] 37.0 98.0 78.0 72.0 25.0 94.0 53.0 15.0 67.0 117.0 88.0 73.0
## [121] 13.0 129.0 109.0 46.0 112.0 58.0 43.0 62.0 34.0 48.0
rank(-Gap_g77$ipp)## [1] 126.0 31.0 71.0 12.0 18.0 9.0 6.0 102.0 17.0 48.0 103.0 74.0
## [13] 66.0 52.0 27.0 24.0 3.0 117.0 125.0 113.0 89.0 70.0 122.0 119.0
## [25] 20.0 72.0 38.0 93.0 129.5 62.0 34.0 81.0 60.0 96.0 40.0 39.0
## [37] 46.0 45.0 56.0 25.0 91.0 127.0 49.0 15.0 110.0 95.0 36.0 54.0
## [49] 108.0 112.0 63.0 101.0 77.0 86.0 55.0 21.0 23.0 42.0 47.0 98.0
## [61] 105.0 4.0 90.0 30.0 104.0 114.0 11.0 111.0 121.0 16.0 32.0 109.0
## [73] 82.0 84.0 26.0 79.0 61.0 65.0 129.5 115.0 50.0 107.0 75.0 124.0
## [85] 80.0 7.0 76.0 29.0 87.0 41.0 51.0 68.0 1.0 123.0 10.0 28.0
## [97] 44.0 67.0 99.0 8.0 92.0 13.0 120.0 5.0 100.0 128.0 35.0 57.0
## [109] 94.0 33.0 53.0 59.0 106.0 37.0 78.0 116.0 64.0 14.0 43.0 58.0
## [121] 118.0 2.0 22.0 85.0 19.0 73.0 88.0 69.0 97.0 83.0
sort(Gap_oecd$ipp)## [1] 13862 14733 15605 16130 17960 20757 21194 24839 25999 28102 29967 33152
## [13] 33872 34705 34887 34950 35393 36536 36765 36902 37189 37534 38844 39385
## [25] 42017 42338 45661 50776 58045 81690
quantile(Gap_oecd$ipp)## 0% 25% 50% 75% 100%
## 13862.0 25129.0 34918.5 38516.5 81690.0
quantile(Gap_g77$ipp)## 0% 25% 50% 75% 100%
## 573.00 2105.00 4431.50 9797.25 108287.00
summary(Gap_oecd$ipp)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 13862 25129 34918 33993 38516 81690
summary(Gap_g77$ipp)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 573 2105 4432 9826 9797 108287
quantile(Gap_oecd$ipp,probs=c(0.01,0.05,0.10,0.25,0.50,0.75,0.90,0.95,0.99))## 1% 5% 10% 25% 50% 75% 90% 95%
## 14114.59 15125.40 16077.50 25129.00 34918.50 38516.50 46172.50 54773.95
## 99%
## 74832.95
quantile(Gap_g77$ipp,probs=c(0.01,0.05,0.10,0.25,0.50,0.75,0.90,0.95,0.99))## 1% 5% 10% 25% 50% 75% 90% 95%
## 581.70 776.60 1074.20 2105.00 4431.50 9797.25 18347.70 43657.75
## 99%
## 97155.50
#Grupo 77
max(Gap_g77$ipp)## [1] 108287
min(Gap_g77$ipp)## [1] 573
max(Gap_g77$ipp)-min(Gap_g77$ipp)## [1] 107714
#OECD
max(Gap_oecd$ipp)## [1] 81690
min(Gap_oecd$ipp)## [1] 13862
max(Gap_oecd$ipp)-min(Gap_oecd$ipp)## [1] 67828
Em estatística, momentos são quantidades relacionadas à forma de um conjunto de números, ou seja, a “aparência do histograma” baseado em medidas numéricas: dispersão, simetria e outras (Schmuller and Batista 2019). Os momentos são um tipo de médias dos números do conjunto em que todo elemento é elevada à k-ésima potência antes da média ser calculada
Primeiro momento: todo elemento é elevado a
1 antes da média ser calculada. Ou seja, o primeiro momento
é a média qye indica a tendência central da distribuição. Essas medidas
foram abordadas na seção sobre a tendência central
Segundo momento: todo elemento é elevado a
2 antes da média ser calculada. Ou seja, o segundo momento
é a variância que indica a dispersão da distribuição. Essas medidas
foram abordadas na seção sobre dispersão.
Terceiro momento: todo elemento é elevado a
3. O terceiro momento indica a assimetria do
histograma.
Quarto momento: todo elemento é elevado a
4. O quarto momento indica a curtose (
leptocúrtico ou platicúrtico) da distribuição
Assimetria
ggplot(CpGoy,aes(x=Cota))+
geom_histogram(binwidth=25,color='black',fill='#5C88DAB2')+
labs(x='Cotas (em metros)',y='Freq',title='Cotas do Rio Paraíba',
subtitle = 'Ponte Leonel Brizola - Campos dos Goytacazes')+
theme_bw()library(moments)
skewness(CpGoy$Cota)## [1] 0.7113064
ggplot(bike_lon,aes(x=hum))+
geom_histogram(binwidth=3,color='black',fill='#5C88DAB2')+
labs(x='Umidade (%)',y='Freq',title='Umidade diária',
subtitle = 'Londres - UK')+
theme_bw()library(moments)
skewness(bike_lon$hum)## [1] -0.5727326
Curtose
library(moments)
x <- c(rep(61, each = 10), rep(64, each = 18),
rep(65, each = 23), rep(67, each = 32), rep(70, each = 27),
rep(73, each = 17))
kurtosis(x)## [1] 2.258318
hist(x)x <- c(rep(61, each = 2), rep(64, each = 5),
rep(65, each = 42), rep(67, each = 12), rep(70, each = 10))
kurtosis(x)## [1] 3.696788
hist(x)x <- c(rep(61, each = 10), rep(64, each = 18),
rep(65, each = 23), rep(67, each = 32), rep(70, each = 27),
rep(73, each = 17))
kurtosis(x)## [1] 2.258318
hist(x)regions_tabfreq<-table(Gapminder_2020$eight_regions)
regions_tabfreq##
## África do Norte África Subsaariana América do Norte América do Sul
## 6 48 23 12
## Ásia Ocidental Extremo Oriente Leste Europeu Europa Ocidental
## 27 32 24 25
prop.table(regions_tabfreq)##
## África do Norte África Subsaariana América do Norte América do Sul
## 0.03045685 0.24365482 0.11675127 0.06091371
## Ásia Ocidental Extremo Oriente Leste Europeu Europa Ocidental
## 0.13705584 0.16243655 0.12182741 0.12690355
round(prop.table(regions_tabfreq),2)##
## África do Norte África Subsaariana América do Norte América do Sul
## 0.03 0.24 0.12 0.06
## Ásia Ocidental Extremo Oriente Leste Europeu Europa Ocidental
## 0.14 0.16 0.12 0.13
margin.table(regions_tabfreq)## [1] 197
library(tidyr)
ipp2020<-Gapminder %>%
filter(time==2020,!is.na(ipp))%>%
select(geo,ipp)
ipp<-hist(ipp2020$ipp,plot=F)
ipp.matrix<-matrix(c(ipp$mids,ipp$breaks[-1],ipp$breaks[-length(ipp$breaks)],ipp$counts),ncol=4)
ipp.df=data.frame(ipp.matrix)
colnames(ipp.df)<-c('PontoCentral','LimInf','LimSup','Frequencia')
cumsum(ipp.df$Frequencia)## [1] 85 131 150 164 180 186 190 192 192 194 194 195
ipp.df$FreqCum<-cumsum(ipp.df$Frequencia)
ipp.df$FreqRel<-ipp.df$Frequencia/sum(ipp.df$Frequencia)
ipp.df$CumRel<-ipp.df$FreqCum/sum(ipp.df$Frequencia)View(ipp.df)plot(ecdf(ipp2020$ipp),xlab='Renda Per Capita (US$)',ylab='Percentil')ggplot(data=ipp2020,aes(x=ipp))+
geom_step(stat='ecdf')+
labs(x='Renda Per Capita (US$)',y='Percentil')ipp.quantile<-quantile(Gapminder$ipp,na.rm=T)
ggplot(data=NULL,aes(x=ipp2020$ipp))+
geom_density(stat='ecdf')+
labs(x='Renda Per Capita (US$)',y='Percentil')+
geom_vline(aes(xintercept = ipp.quantile),linetype='dashed')ipp.quantile<-quantile(Gapminder$ipp,na.rm=T)
ggplot(data=NULL,aes(x=ipp2020$ipp))+
geom_density(stat='ecdf')+
labs(x='Renda Per Capita (US$)',y='Percentil')+
geom_vline(aes(xintercept = ipp.quantile),linetype='dashed')+
scale_x_continuous(breaks=ipp.quantile,labels=label_comma(ipp.quantile,scale=10^-3,accuracy =1))ipp.quantile<-quantile(Gapminder$ipp,na.rm=T)
ggplot(data=NULL,aes(x=ipp2020$ipp))+
geom_density(stat='ecdf')+
labs(x='Renda Per Capita (US$)',y='Percentil')+
geom_vline(aes(xintercept = ipp.quantile),linetype='dashed')+
scale_x_log10(breaks=ipp.quantile,labels=label_comma(ipp.quantile,scale=10^-3,accuracy =1))ipp.rounded<-round(sort(ipp2020$ipp),0)
ipp.rounded## [1] 628 633 817 845 974 1126 1207 1208 1419 1499
## [11] 1524 1620 1639 1649 1677 1714 1793 1800 1861 1919
## [21] 1947 2002 2060 2138 2166 2229 2314 2329 2412 2497
## [31] 2516 2900 2910 2913 3019 3057 3086 3228 3260 3263
## [41] 3456 3550 3592 3651 3652 3710 3873 3949 4025 4090
## [51] 4291 4401 4530 4539 4590 4683 4716 5020 5110 5297
## [61] 5444 6129 6456 6615 6787 6982 7005 7168 7287 7316
## [71] 7353 7611 7634 7719 7778 7977 8198 8348 8370 8436
## [81] 8637 8770 9054 9507 9664 10122 10194 10233 10242 10865
## [91] 11295 11301 11431 11756 11874 11986 12326 12430 12538 12772
## [101] 13195 13225 13327 13436 13475 13988 14040 14091 14364 14501
## [111] 14600 14668 14864 15928 16004 16044 16394 16509 16697 17115
## [121] 17135 17190 17397 17661 17742 17854 18063 18070 18192 18212
## [131] 18478 20915 21331 22659 23279 24254 25007 25330 25474 26002
## [141] 26154 26339 26422 28087 28297 28472 28819 29700 29789 29967
## [151] 30642 30854 32870 32914 33521 34427 34636 34988 35139 35971
## [161] 36084 36155 36725 38017 40062 40351 40387 40740 42005 42921
## [171] 43855 44533 44939 45797 46744 47345 47445 47689 48202 48910
## [181] 51215 55047 57225 57530 57909 59085 61996 64288 65306 67521
## [191] 74059 75053 90474 95116 116162
cat(ipp.rounded,fill=50)## 628 633 817 845 974 1126 1207 1208 1419 1499 1524
## 1620 1639 1649 1677 1714 1793 1800 1861 1919 1947
## 2002 2060 2138 2166 2229 2314 2329 2412 2497 2516
## 2900 2910 2913 3019 3057 3086 3228 3260 3263 3456
## 3550 3592 3651 3652 3710 3873 3949 4025 4090 4291
## 4401 4530 4539 4590 4683 4716 5020 5110 5297 5444
## 6129 6456 6615 6787 6982 7005 7168 7287 7316 7353
## 7611 7634 7719 7778 7977 8198 8348 8370 8436 8637
## 8770 9054 9507 9664 10122 10194 10233 10242 10865
## 11295 11301 11431 11756 11874 11986 12326 12430
## 12538 12772 13195 13225 13327 13436 13475 13988
## 14040 14091 14364 14501 14600 14668 14864 15928
## 16004 16044 16394 16509 16697 17115 17135 17190
## 17397 17661 17742 17854 18063 18070 18192 18212
## 18478 20915 21331 22659 23279 24254 25007 25330
## 25474 26002 26154 26339 26422 28087 28297 28472
## 28819 29700 29789 29967 30642 30854 32870 32914
## 33521 34427 34636 34988 35139 35971 36084 36155
## 36725 38017 40062 40351 40387 40740 42005 42921
## 43855 44533 44939 45797 46744 47345 47445 47689
## 48202 48910 51215 55047 57225 57530 57909 59085
## 61996 64288 65306 67521 74059 75053 90474 95116
## 116162
stem(ipp2020$ipp)##
## The decimal point is 4 digit(s) to the right of the |
##
## 0 | 11111111112222222222222222222233333333333444444444445555555556677777+3
## 1 | 000000111122222333333344445555666677777788888888
## 2 | 1133455566668889
## 3 | 00011334455566678
## 4 | 0001234556777889
## 5 | 157889
## 6 | 2458
## 7 | 45
## 8 |
## 9 | 05
## 10 |
## 11 | 6
summary(Gapminder)## geo name four_regions
## afg : 301 Afghanistan : 301 África :16254
## ago : 301 Albania : 301 Américas:10535
## alb : 301 Algeria : 301 Asia :17759
## and : 301 Andorra : 301 Europa :14749
## are : 301 Angola : 301
## arg : 301 Antigua and Barbuda: 301
## (Other):57491 (Other) :57491
## eight_regions six_regions
## África Subsaariana:14448 América :10535
## Extremo Oriente : 9632 Extremo Oriente : 9632
## Ásia Ocidental : 8127 Europa Central e Ásia Ocidental:16254
## Europa Ocidental : 7525 Oriente Médio e Norte da África: 6020
## Leste Europeu : 7224 Sul da Ásia : 2408
## América do Norte : 6923 África Subsaariana :14448
## (Other) : 5418
## members_oecd_g77 Lat Long Dt_UNMember
## g77 :39130 Min. :-42.00 Min. :-175.00 Min. :1945-10-24
## oecd : 9030 1st Qu.: 4.00 1st Qu.: -5.50 1st Qu.:1945-12-27
## others:10836 Median : 17.50 Median : 21.75 Median :1960-09-28
## NA's : 301 Mean : 19.15 Mean : 22.95 Mean :1965-09-09
## 3rd Qu.: 40.00 3rd Qu.: 51.52 3rd Qu.:1977-09-20
## Max. : 65.00 Max. : 179.14 Max. :2011-07-14
## NA's :1204
## WB_reg WB_income2017 time
## Europe & Central Asia :15652 Low income : 9331 Min. :1800
## Sub-Saharan Africa :14448 Lower middle income:15652 1st Qu.:1875
## Latin America & Caribbean : 9933 Upper middle income:16555 Median :1950
## East Asia & Pacific : 9632 High income :17458 Mean :1950
## Middle East & North Africa: 6321 NA's : 301 3rd Qu.:2025
## (Other) : 3010 Max. :2100
## NA's : 301
## pop ipp gdp tfr
## Min. :6.450e+02 Min. : 245 Min. :1.016e+06 Min. :0.900
## 1st Qu.:4.253e+05 1st Qu.: 901 1st Qu.:4.880e+08 1st Qu.:2.160
## Median :2.627e+06 Median : 1750 Median :3.405e+09 Median :5.100
## Mean :2.312e+07 Mean : 6486 Mean :1.600e+11 Mean :4.501
## 3rd Qu.:1.082e+07 3rd Qu.: 4855 3rd Qu.:2.918e+10 3rd Qu.:6.380
## Max. :1.651e+09 Max. :179297 Max. :5.046e+13 Max. :8.870
## NA's :12302 NA's :12302 NA's :3311
## le cm co2
## Min. : 1.01 Min. : 0.25 Min. : 0.00
## 1st Qu.:32.30 1st Qu.: 15.67 1st Qu.: 0.19
## Median :48.73 Median :179.09 Median : 0.95
## Mean :53.09 Mean :209.17 Mean : 3.31
## 3rd Qu.:74.25 3rd Qu.:403.44 3rd Qu.: 4.00
## Max. :94.76 Max. :756.29 Max. :247.00
## NA's :3167 NA's :1800 NA's :42415
library(Hmisc)
describe(Gapminder)## Gapminder
##
## 19 Variables 59297 Observations
## --------------------------------------------------------------------------------
## geo
## n missing distinct
## 59297 0 197
##
## lowest : afg ago alb and are, highest: wsm yem zaf zmb zwe
## --------------------------------------------------------------------------------
## name
## n missing distinct
## 59297 0 197
##
## lowest : Afghanistan Albania Algeria Andorra Angola
## highest: Venezuela Vietnam Yemen Zambia Zimbabwe
## --------------------------------------------------------------------------------
## four_regions
## n missing distinct
## 59297 0 4
##
## Value África Américas Asia Europa
## Frequency 16254 10535 17759 14749
## Proportion 0.274 0.178 0.299 0.249
## --------------------------------------------------------------------------------
## eight_regions
## n missing distinct
## 59297 0 8
##
## lowest : África do Norte África Subsaariana América do Norte América do Sul Ásia Ocidental
## highest: América do Sul Ásia Ocidental Extremo Oriente Leste Europeu Europa Ocidental
##
## África do Norte (1806, 0.030), África Subsaariana (14448, 0.244), América do
## Norte (6923, 0.117), América do Sul (3612, 0.061), Ásia Ocidental (8127,
## 0.137), Extremo Oriente (9632, 0.162), Leste Europeu (7224, 0.122), Europa
## Ocidental (7525, 0.127)
## --------------------------------------------------------------------------------
## six_regions
## n missing distinct
## 59297 0 6
##
## lowest : América Extremo Oriente Europa Central e Ásia Ocidental Oriente Médio e Norte da África Sul da Ásia
## highest: Extremo Oriente Europa Central e Ásia Ocidental Oriente Médio e Norte da África Sul da Ásia África Subsaariana
##
## América (10535, 0.178), Extremo Oriente (9632, 0.162), Europa Central e Ásia
## Ocidental (16254, 0.274), Oriente Médio e Norte da África (6020, 0.102), Sul da
## Ásia (2408, 0.041), África Subsaariana (14448, 0.244)
## --------------------------------------------------------------------------------
## members_oecd_g77
## n missing distinct
## 58996 301 3
##
## Value g77 oecd others
## Frequency 39130 9030 10836
## Proportion 0.663 0.153 0.184
## --------------------------------------------------------------------------------
## Lat
## n missing distinct Info Mean Gmd .05 .10
## 59297 0 160 1 19.15 27.1 -22.00 -14.33
## .25 .50 .75 .90 .95
## 4.00 17.50 40.00 49.00 55.42
##
## lowest : -42.00000 -34.00000 -33.45694 -33.00000 -29.50000
## highest: 60.00000 60.10867 62.00000 64.00000 65.00000
## --------------------------------------------------------------------------------
## Long
## n missing distinct Info Mean Gmd .05 .10
## 59297 0 171 1 22.95 73.33 -85.00 -70.67
## .25 .50 .75 .90 .95
## -5.50 21.75 51.52 114.67 147.00
##
## lowest : -175.00000 -172.13333 -113.64258 -99.12766 -98.50000
## highest: 171.23600 172.98400 174.00000 178.00000 179.14478
## --------------------------------------------------------------------------------
## Dt_UNMember
## n missing distinct Info Mean Gmd .05
## 58093 1204 93 0.996 1965-09-09 7323 1945-10-24
## .10 .25 .50 .75 .90 .95
## 1945-10-24 1945-12-27 1960-09-28 1977-09-20 1992-05-22 1994-12-15
##
## lowest : 1945-10-24 1945-10-25 1945-10-30 1945-10-31 1945-11-01
## highest: 2000-11-01 2002-09-10 2002-09-27 2006-06-28 2011-07-14
## --------------------------------------------------------------------------------
## WB_reg
## n missing distinct
## 58996 301 7
##
## lowest : East Asia & Pacific Europe & Central Asia Latin America & Caribbean Middle East & North Africa North America
## highest: Latin America & Caribbean Middle East & North Africa North America South Asia Sub-Saharan Africa
##
## East Asia & Pacific (9632, 0.163), Europe & Central Asia (15652, 0.265), Latin
## America & Caribbean (9933, 0.168), Middle East & North Africa (6321, 0.107),
## North America (602, 0.010), South Asia (2408, 0.041), Sub-Saharan Africa
## (14448, 0.245)
## --------------------------------------------------------------------------------
## WB_income2017
## n missing distinct
## 58996 301 4
##
## Value Low income Lower middle income Upper middle income
## Frequency 9331 15652 16555
## Proportion 0.158 0.265 0.281
##
## Value High income
## Frequency 17458
## Proportion 0.296
## --------------------------------------------------------------------------------
## time
## n missing distinct Info Mean Gmd .05 .10
## 59297 0 301 1 1950 100.3 1815 1830
## .25 .50 .75 .90 .95
## 1875 1950 2025 2070 2085
##
## lowest : 1800 1801 1802 1803 1804, highest: 2096 2097 2098 2099 2100
## --------------------------------------------------------------------------------
## pop
## n missing distinct Info Mean Gmd .05 .10
## 59297 0 56397 1 23123071 39537248 25000 60810
## .25 .50 .75 .90 .95
## 425280 2626649 10817133 44170528 81900642
##
## lowest : 645 649 661 670 685
## highest: 1650350924 1650996767 1651018523 1651342347 1651349931
## --------------------------------------------------------------------------------
## ipp
## n missing distinct Info Mean Gmd .05 .10
## 46995 12302 13856 1 6486 9182 524 615
## .25 .50 .75 .90 .95
## 901 1750 4855 17101 32436
##
## lowest : 245 246 247 248 249, highest: 176115 177262 177977 178635 179297
## --------------------------------------------------------------------------------
## gdp
## n missing distinct Info Mean Gmd .05 .10
## 46995 12302 45799 1 1.6e+11 2.979e+11 3.000e+07 7.565e+07
## .25 .50 .75 .90 .95
## 4.880e+08 3.405e+09 2.918e+10 1.992e+11 5.051e+11
##
## lowest : 1.016036e+06 1.017870e+06 1.020260e+06 1.024488e+06 1.030557e+06
## highest: 4.688632e+13 4.777179e+13 4.866233e+13 4.955834e+13 5.045991e+13
## --------------------------------------------------------------------------------
## tfr
## n missing distinct Info Mean Gmd .05 .10
## 55986 3311 753 1 4.501 2.317 1.68 1.76
## .25 .50 .75 .90 .95
## 2.16 5.10 6.38 6.90 7.06
##
## lowest : 0.90 0.95 0.96 0.97 0.98, highest: 8.80 8.83 8.85 8.86 8.87
## --------------------------------------------------------------------------------
## le
## n missing distinct Info Mean Gmd .05 .10
## 56130 3167 7178 1 53.09 24.53 26.09 28.95
## .25 .50 .75 .90 .95
## 32.30 48.73 74.25 82.76 86.18
##
## lowest : 1.01 1.10 1.50 4.00 4.07, highest: 94.54 94.62 94.65 94.73 94.76
## --------------------------------------------------------------------------------
## cm
## n missing distinct Info Mean Gmd .05 .10
## 57497 1800 20531 1 209.2 207 2.02 3.85
## .25 .50 .75 .90 .95
## 15.67 179.09 403.44 443.79 480.98
##
## lowest : 0.25 0.26 0.27 0.28 0.29, highest: 675.58 677.30 679.68 682.08 756.29
## --------------------------------------------------------------------------------
## co2
## n missing distinct Info Mean Gmd .05 .10
## 16882 42415 3291 1 3.312 4.681 0.01791 0.05040
## .25 .50 .75 .90 .95
## 0.19400 0.95300 4.00000 9.07000 12.60000
##
## lowest : 0.00e+00 6.00e-05 7.00e-05 8.00e-05 9.00e-05
## highest: 9.29e+01 9.95e+01 1.01e+02 1.19e+02 2.47e+02
## --------------------------------------------------------------------------------
x<-rnorm(1000,100,15)
ggplot(NULL,aes(x=x))+
geom_histogram(fill='lightblue',col='black',binwidth = 5)ggplot(IQ,aes(x=iq))+
geom_histogram(fill='lightblue',col='black',binwidth = 5)vertical.lines<-seq(55,145,15)
ggplot(IQ,aes(x=iq))+
geom_histogram(fill='lightblue',col='black',binwidth = 5)+
scale_x_continuous(breaks=vertical.lines,labels=vertical.lines)+
sapply(vertical.lines, function(xint) geom_vline(aes(xintercept = xint),linetype='dashed'))Toda função que trata as distribuições de probabilidade no R usam a
mesma notação. As letras d, p,q e
r identificam se a função irá retornar a função
densidade, a probabilidade, a quantis e para
gerar números aleatórios ( randon ), respectivamente. Na
sequencia vem um texto que define qual distribuição a se refere. Por
exemplo:
r:
runif(n=6,min=1,max=60) irá gerar uma
sequencia de 6 números aleatórios entre um e 60rbinom(n=10,size=1,prob=0.5) irá gerar um
sequencia de 10 valores entre zero e umd
(probabilidade contínua)
dnorm(x=130,mean=100,sd=15) irá retornar o
valor da função \(f(x)\) quando
substituimos o x na fórmula a seguir, considerando a média
\(\mu=100\) e pelo desvio padrão \(\sigma=15\).\[ f(x)=\frac1{\sqrt{2\pi\sigma^2}}{exp}^\frac{x-\mu}{\sigma} \]
d
(probabilidade discreta)
dpois(x=4,lambda=2) irá retornar a probabilidade de \(x=4\), considerando uma distribuição de
Poisson, com média e desvio padrão \(\lambda=2\) (fórmula a seguir).\[ p(x) = \frac{{e^{ - \lambda } \lambda ^x }}{{x!}} \]
p são
as funções de densidade acumulada
pnorm(q=1.13,mean=0,sd=1) retorna o
valor da probabildaide acumulada entre\(-\infty\) a 1.13. É o mesmo
que consultar a tabela normal padrão (\(\mu=0\) e \(\sigma=1\)) e procurar pelo número
1.13 na tabela normal padrão como a apresedntada na figura
seguir.Exemplo de uma tabela normal padrão
q são as
funções de inversas das funções de densidade
qnorm(p=0.8708,mean=0,sd=1) retorna o
valor de x cuja probailidade acumulada entre\(-\infty\) a x é
0.8708 É o mesmo que consultar a tabela normal padrão
(\(\mu=0\) e \(\sigma=1\)) e procurar pelo número
0.8708 no meio da tabela apresentada anteriormente e
procurar pelo valor de x (1.13).x.values<-seq(40,160,1)
sd.values<-seq(40,160,15)
zeros9<-rep(0,9)
ggplot(NULL, aes(x=x.values,y=dnorm(x.values,m=100,s=15)))+
geom_line()+
labs(x="IQ",y='f(IQ)')+
scale_x_continuous(breaks = sd.values,labels=sd.values)+
scale_y_continuous(expand=c(0,0))+
geom_segment(aes(x=sd.values,y=zeros9,xend=sd.values,yend=dnorm(sd.values,m=100,s=15)),
linetype='dashed')ggplot(NULL, aes(x=x.values,y=pnorm(x.values,m=100,s=15)))+
geom_line()+
labs(x="IQ",y='f(IQ)')+
scale_x_continuous(breaks = sd.values,labels=sd.values)+
scale_y_continuous(expand=c(0,0))+
geom_segment(aes(x=sd.values,y=zeros9,xend=sd.values,yend=pnorm(sd.values,m=100,s=15)),
linetype='dashed')Qual é a probabilidade de encontrarmos uma pessoa com QI maior que 85 e menor que 100?
library(tigerstats)
pnormGC(c(85,100),region='between',m=100,sd=15,graph=T)## [1] 0.3413447
qnormGC(0.1586553,m=100,sd=15,graph=T)## [1] 85
qnormGC(0.1586553,m=100,sd=15,graph=T,region='below')## [1] 85
qnormGC(0.1586553,m=100,sd=15,graph=T,region='above')## [1] 115
qnormGC(0.1586553,m=100,sd=15,graph=T,region='outside')## [1] 78.85587 121.14413
qnorm(c(0,.25,.5,.75,1),m=100,sd=15)## [1] -Inf 89.88265 100.00000 110.11735 Inf
round(qnorm(c(.05,.25,.5,.75,.95),m=100,sd=15),0)## [1] 75 90 100 110 125
q.values<-round(qnorm(c(.25,.5,.75),m=100,sd=15),0)
zeros3<-c(0,0,0)
ggplot(NULL, aes(x=x.values,y=pnorm(x.values,m=100,s=15)))+
geom_line()+
labs(x="IQ",y='f(IQ)')+
scale_x_continuous(breaks = q.values,labels=q.values)+
scale_y_continuous(expand=c(0,0))+
geom_segment(aes(x=q.values,y=zeros3,xend=q.values,yend=pnorm(q.values,m=100,s=15)),
linetype='dashed')rnorm(n=5,m=100,sd=15)## [1] 105.80006 93.71624 95.14190 98.39368 85.61893
rnorm(n=5,m=100,sd=15)## [1] 111.63519 114.24520 88.29500 96.96716 86.98895
set.seed(7637060)
rnorm(n=5,m=100,sd=15)## [1] 71.99120 98.67231 92.68848 103.42207 99.61904
set.seed(7637060)
rnorm(n=5,m=100,sd=15)## [1] 71.99120 98.67231 92.68848 103.42207 99.61904
Média \(\mu=0\) Desvio Padrãop \(\sigma=1\)
dnorm(0)## [1] 0.3989423
pnorm(0)## [1] 0.5
qnorm(c(0.25,.5,.75))## [1] -0.6744898 0.0000000 0.6744898
rnorm(5)## [1] 0.9155883 -2.4263919 -0.9018797 1.4056493 0.5340863
pnormGC(c(-1,0),region='between',graph=T)## [1] 0.3413447
pnormGC(c(-1,0),region='outside',graph=T)## [1] 0.6586553
pnormGC(-1,region='below',graph=T)## [1] 0.1586553
pnormGC(-1,region='above',graph=T)## [1] 0.8413447
z.values<-seq(-4,4,.01)
z.sd.values<-seq(-4,4,1)
ggplot(NULL, aes(x=z.values,y=dnorm(z.values)))+
geom_line()+
labs(x="z",y='f(z)')+
scale_x_continuous(breaks = z.sd.values,labels=z.sd.values)+
scale_y_continuous(expand=c(0,0))+
geom_segment(aes(x=z.sd.values,y=zeros9,xend=z.sd.values,yend=dnorm(z.sd.values)),
linetype='dashed')#knitr::purl('Descrevendo_dados.Rmd')