Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Presion

library(readxl);library(tidyverse)

## ── Attaching core tidyverse packages ────────────────────────


tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.2.0
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ──────────────────────────────────────────
tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to
force all conflicts to become errors

Clima_Madrid_2018<-read_excel("C:/Users/Descarga/Clima_Madrid_2018.xlsx")

datosPre<-as.data.frame(Clima_Madrid_2018$pressure)
datosPre

## Clima_Madrid_2018$pressure

#2
library(ggplot2)
ggplot(data = datosPre,mapping = aes(x= Clima_Madrid_2018$pressure))+
geom_histogram(bins = 8,fill="lightcyan",color="blue")+
theme_classic()+
scale_x_continuous(n.breaks = 8)+
labs(x="pressure",y="cantidad")

#3
library(fitdistrplus)

## Loading required package: MASS

##
## Attaching package: 'MASS'

## The following object is masked from 'package:dplyr':


##
## select

## Loading required package: survival

#m_weibull<- fitdist(datosPre$`Clima_Madrid_2018$pressure`,
"weibull",method = "mle")
#m_gamma<- fitdist(datosPre$`Clima_Madrid_2018$pressure`, "gamma",method
= "mle")
m_normal<- fitdist(datosPre$`Clima_Madrid_2018$pressure`, "norm",method =
"mle")
plot.legend<- c("norm")
gofstat(m_normal, fitnames = c("normal"))
## Goodness-of-fit statistics
## normal
## Kolmogorov-Smirnov statistic 0.1592717
## Cramer-von Mises statistic 50.4890805
## Anderson-Darling statistic 280.2473620
##
## Goodness-of-fit criteria
## normal
## Akaike's Information Criterion 70139.63
## Bayesian Information Criterion 70153.92

# Hist
denscomp(list(m_normal), legendtext = plot.legend,datacol =
"#FFE4E1",fitlwd = 0.8,plotstyle ="ggplot",breaks =8)+theme_classic()+
scale_x_continuous(n.breaks = 8)

## Warning: The dot-dot notation (`..density..`) was deprecated in


ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## ℹ The deprecated feature was likely used in the fitdistrplus package.
## Please report the issue at
<]8;;https://github.com/aursiber/fitdistrplus/issueshttps://github.com/
aursiber/fitdistrplus/issues]8;;>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning
was
## generated.
#Q-Q plot
qqcomp(list(m_normal), legendtext = plot.legend,fitpch =
c(15,16,17),plotstyle = "ggplot",fitlwd = 2.5)+theme_classic()

Interpretacion: Solo tiene como mejor modelo la normaL, ya que, la distribucion es


normal
AIC 70139.63 BIC 70153.92
m_normal$estimate

## mean sd
## 1015.91920 10.11544

EX<-m_normal$estimate[1]
EX

## mean
## 1015.919

SX<-m_normal$estimate[2]
SX

## sd
## 10.11544

muestra<-data.frame(x=rnorm(n = 867,mean =14.26664 ,sd = 8.997715))

library(boot)
##
## Attaching package: 'boot'

## The following object is masked from 'package:survival':


##
## aml

meanfun <- function(data, i){


d <- data[i, ]
return(mean(d))
}
simulacion<-boot(muestra[, "x", drop = FALSE], statistic=meanfun, R=100)
Estimador<-mean(simulacion$t)
Estimador

## [1] 14.08055

hist(simulacion$t,
labels=TRUE,
col = "lightblue",
main = "",
xlab ="temperature",
ylab ="Cantidad",
ylim = c(0,70),
right = FALSE,
nclass = 5)
Intervalo<-boot.ci(simulacion,cont=0.95,type="norm")
Intervalo

## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS


## Based on 100 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = simulacion, type = "norm", cont = 0.95)
##
## Intervals :
## Level Normal
## 95% (13.46, 14.72 )
## Calculations and Intervals on Original Scale

abline(v = Intervalo$normal,col="red",lwd=2,lty=3)
data.frame(Parámetro=EX,Estimador=Estimador,Sesgo=Estimador-EX)

## Parámetro Estimador Sesgo


## mean 1015.919 14.08055 -1001.839
Temperatura
library(readxl)
Clima_Madrid_2018 <-
read_excel("C:/Users/Descarga/Clima_Madrid_2018.xlsx")

1
datos<-as.data.frame(Clima_Madrid_2018$Temperature)
datos

## Clima_Madrid_2018$Temperature

#2.
library(ggplot2)
ggplot(data = datos,mapping = aes(x = Clima_Madrid_2018$Temperature))+
geom_histogram(bins = 8,fill="lightcyan",color="blue")+
theme_classic()+
scale_x_continuous(n.breaks = 8)+
labs(x="temperature",y="Cantidad")

Interpretacion: 1.Rango: toma valores en el eje x, valor minimo 10 y el maximo es 40.


2.posicion
3.forma:sesgada a la derecha.
#3.
library(fitdistrplus)

## Loading required package: MASS

## Loading required package: survival

#m_weibull<- fitdist(datos$`Clima_Madrid_2018$Temperature`,
"weibull",method = "mle")
#m_gamma<- fitdist(datos$`Clima_Madrid_2018$Temperature`, "gamma",method
= "mle")
m_normal<- fitdist(datos$`Clima_Madrid_2018$Temperature`, "norm",method =
"mle")
plot.legend<- c("norm")
gofstat(m_normal, fitnames = c("normal"))

## Goodness-of-fit statistics
## normal
## Kolmogorov-Smirnov statistic 0.08248635
## Cramer-von Mises statistic 16.72664965
## Anderson-Darling statistic 100.18955159
##
## Goodness-of-fit criteria
## normal
## Akaike's Information Criterion 67939.7
## Bayesian Information Criterion 67954.0

# Hist
denscomp(list(m_normal), legendtext = plot.legend,datacol =
"#FFE4E1",fitlwd = 0.8,plotstyle ="ggplot",breaks =8)+theme_classic()+
scale_x_continuous(n.breaks = 8)

## Warning: The dot-dot notation (`..density..`) was deprecated in


ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## ℹ The deprecated feature was likely used in the fitdistrplus package.
## Please report the issue at
<]8;;https://github.com/aursiber/fitdistrplus/issueshttps://github.com/
aursiber/fitdistrplus/issues]8;;>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning
was
## generated.
#Q-Q plot
qqcomp(list(m_normal), legendtext = plot.legend,fitpch =
c(15,16,17),plotstyle = "ggplot",fitlwd = 2.5)+theme_classic()
Interpretacion: el mejor modelo es la normal, ya que no se hallan otros modelos
debido a que la distribucion normal es la que modela numeros positivos y negativos.
#4.
m_normal$estimate

## mean sd
## 14.266637 8.997715

#5.
EX<-m_normal$estimate[1]
EX

## mean
## 14.26664

SX<-m_normal$estimate[2]
SX

## sd
## 8.997715

#6.
muestra<-data.frame(x=rnorm(n = 867,mean =14.26664 ,sd = 8.997715))

library(boot)

##
## Attaching package: 'boot'

## The following object is masked from 'package:survival':


##
## aml

meanfun <- function(data, i){


d <- data[i, ]
return(mean(d))
}
simulacion<-boot(muestra[, "x", drop = FALSE], statistic=meanfun, R=100)
Estimador<-mean(simulacion$t)
Estimador

## [1] 13.62256

hist(simulacion$t,
labels=TRUE,
col = "lightblue",
main = "",
xlab ="temperature",
ylab ="Cantidad",
ylim = c(0,70),
right = FALSE,
nclass = 5)
Intervalo<-boot.ci(simulacion,cont=0.95,type="norm")
Intervalo

## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS


## Based on 100 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = simulacion, type = "norm", cont = 0.95)
##
## Intervals :
## Level Normal
## 95% (13.11, 14.26 )
## Calculations and Intervals on Original Scale

abline(v = Intervalo$normal,col="red",lwd=2,lty=3)

data.frame(Parámetro=EX,Estimador=Estimador,Sesgo=Estimador-EX)

## Parámetro Estimador Sesgo


## mean 14.26664 13.62256 -0.6440726

You might also like