You are on page 1of 6

f.

R
USUARIO

Mon Sep 18 09:43:52 2017


coefint=c(110,100,115,105,104) #intervalo de confianza
t.test(coefint,conf.level = 0.95) # 0.95--> 95% confianzam

##
## One Sample t-test
##
## data: coefint
## t = 41.138, df = 4, p-value = 2.087e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 99.59193 114.00807
## sample estimates:
## mean of x
## 106.8

##
muestra <- c(260,230,179,230,245,170)
t.test(muestra, conf.level = 0.90)

##
## One Sample t-test
##
## data: muestra
## t = 14.765, df = 5, p-value = 2.576e-05
## alternative hypothesis: true mean is not equal to 0
## 90 percent confidence interval:
## 189.112 248.888
## sample estimates:
## mean of x
## 219

var(muestra)#varianza

## [1] 1320

sum( (muestra-mean(muestra))^2 )/(length(muestra)-1)#varinza

## [1] 1320

summary(muestra)

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## 170.0 191.8 230.0 219.0 241.2 260.0
###Modelos de probablilidad
plot(dbinom(0:10,10,0.6),type="h",xlab="k",ylab="P(X=k)",main="Funcin de
Probabilidad B(10,0.6)")

##
plot(stepfun(0:10,pbinom(0:11,10,0.6)),xlab="k",ylab="F(k)",main="Funcin de
distribucin B(10,0.6)")
##
curve(dnorm(x,170,12),xlim=c(130,210),col="blue",lwd=2,
xlab="x",ylab="f(x)",main="Funcin de Densidad N(170,12)")
##norm
regionX=seq(150,168,0.01) # Intervalo a sombrear
xP <- c(150,regionX,168) # Base de los polgonos que crean el
efecto "sombra"
yP <- c(0,dnorm(regionX,170,12),0) # Altura de los polgonos sombreados
curve(dnorm(x,170,12),xlim=c(130,210),yaxs="i",ylim=c(0,0.035),ylab="f(x)",
main='Densidad N(170,12)')
polygon(xP,yP,col="cyan", border = "coral1")
box()

##
X=rnorm(10000, 170, 12)
hist(X,freq=FALSE,col="lightsalmon",main="Histograma",sub="Datos simulados de
una N(170,12)")
curve(dnorm(x,170,12),xlim=c(110,220),col="red2",lwd=2,add=TRUE)
##
mediaMuestral=function(n){
muestra=rnorm(n,170,12)
media=mean(muestra)
return(media)
}
mediaMuestral(25)

## [1] 169.7123

m=10000
muchasMedias=replicate(m,mediaMuestral(25))
muchasMedias[1:20]

## [1] 172.0544 172.9546 169.1314 169.8210 172.5374 168.5118 171.7875


## [8] 168.4766 171.2684 173.4052 167.6402 170.4995 172.0247 168.1762
## [15] 171.7127 166.5579 171.0616 171.6263 169.9459 167.5439

hist(muchasMedias,xlab="Media muestral", ylab="Frecuencia", col="cyan",


xlim=c(160,180),freq=FALSE,ylim=c(0,0.75),
main="Histograma de las medias muestrales observadas\n en 10000 muestras
de tamao 25")
curve(dnorm(x,170,sd(muchasMedias)),xlim=c(160,180),col="blue",lwd=2,add=TRUE
)

You might also like