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

#Distribución de medias

library(gtools)

N <- 6

n<- 3

P <- c(1:N)

C <- combinations(N,n,secre)

c1 <- C[1,]

mean(v)

m <- rowMeans(C)

mf <- apply(C,1,mean)

mean(m)

mean(mf)

mean(P)

sd(P)

1.870829^2

d <- apply(C,1,sd)

v <- apply(C,1,var)

mean(v)

mean(d)

sqrt(3.5)

hist(m)

table(round(m,2))

tm <- table(round(m,2))

pm <- prop.table(tm)

plot(pm)

#Distribuciones

names(Bsec1ec)

boxplot(Bsec1ec$Edad)

hist(Bsec1ec$Edad)

hist(Bsec1ec$Edad, freq = FALSE)


lines(density(Bsec1ec$Edad))

#Retiro de un dato

Nbsec10 <- subset(Bsec1ec,10<Edad)

boxplot(Nbsec10$Edad)

hist(Nbsec10$Edad)

hist(Nbsec10$Edad, freq = FALSE)

lines(density(Nbsec10$Edad))

Nbsec25 <- subset(Nbsec10,Edad<25)

boxplot(Nbsec25$Edad)

hist(Nbsec25$Edad)

table(Nbsec25$Edad)

hist(Nbsec25$Edad, freq = FALSE)

lines(density(Nbsec25$Edad))

e <- Nbsec25$Edad

table(e)

mean(e)

median(e)

library(moments)

library(modeest)

mfv(e)

m <-mean(e)

sd(e)

s <-sd(e)

hist(e)

hist(e, freq = FALSE)

lines(density(e))

z <- (e-mean(e))/sd(e)

mean(z)

sd(z)

hist(z)

hist(z, freq = FALSE)


lines(density(z))

boxplot(Nbsec25$Edad,col =c("green"))

media <- c(mean(Nbsec25$Edad))#Muestra la Media un punto

points(media,pch=10,col="red")#Resalta la media derojo

hist(Nbsec25$Edad, freq = FALSE, ylim = c(0,0.5),xlim = c(17,24),

col =c("green"), main = "Talla, Alumos Ec I")

lines(density(Nbsec25$Edad),col =c("red"), lwd=4)

#generalizando z

z <- seq(-4,4,length=1000)#

mean(z)

sd(z)

#Con función de R

y=dnorm(z,mean=0,sd=1)

plot(z,y,type="l",lwd=2,col="green")

abline(v=2,lty=10,col="blue")

abline(v=-2,lty=20,col="brown")

#Calculo de probabilidad

#No mayoy a 21 años

pnorm(21,mean=20,sd=1.231312,lower.tail = TRUE)

pnorm(21,mean=20,sd=1.231312,lower.tail = FALSE)

p28 <-pnorm(28,mean=29.65,sd=3.73,lower.tail = TRUE)

p32 <-pnorm(32,mean=29.65,sd=3.73,lower.tail = TRUE)

ppi <-p32-p28

z1 <- (34-29.65)/3.73

pnorm(z1)

#Distribución t

x <- seq(-6, 6, length = 100)#genera variable

df = c(1,4,10,30)

colour = c("red", "orange", "green", "yellow","black")


plot(x, dnorm(x), type = "l", lty = 2, xlab = "t-value", ylab = "Density",

main = "Comparison of t-distributions", col = "black")

for (i in 1:4){

lines(x, dt(x, df[i]), col = colour[i])

legend("topright", c("df = 1", "df = 4", "df = 10", "df = 30", "normal"),

col = colour, title = "t-distributions", lty = c(1,1,1,1,2))

g<- seq(- 5, 5, by = 0.01)#generando variable

s<- dt(s, df = 3)

plot(s, type = "l", main = "t-distribution density function example", las=1)

a<- pt(g, df = 3)

plot(a, type = "l", main = "t-distribution cumulative function example", las=1)

#Distribución chi

#Chi cuadrado; Suma de variables aleatorias normalizadas

curve(dchisq(x,1),xlim=c(0,15),ylim=c(0,0.5),ylab="Chi Square Density")

curve(dchisq(x,2),col="red",lty=2,add=TRUE)

curve(dchisq(x,3),col="blue",lty=3,add=TRUE)

curve(dchisq(x,5),col="dark green",lty=4,add=TRUE)

curve(dchisq(x,10),col="brown",lty=5,add=TRUE)

legend(12,0.55,c("k=1","k=2","k=3","k=5","k=10"),

col=c("black","red","blue","dark green","brown"),lty=1:5)

###F distribución

xp = seq(0, 5, length = 1000)

y=df(x=xp,df1=4,df2=44)

curve(df(x, df1=4, df2=44), from=0, to=5, main="Distribucion F")

F.critico=3.061

polygon(c(F.critico, F.critico, xp[xp>F.critico], max(xp)),

c(0, df(F.critico, df1=4, df2=44), y[xp>F.critico], 0),

col = "blue")

f1 <- qf(0.95, df1 = 3, df2 = 5)

p1 <- pf(5.409, df1 = 3, df2 = 5)


#Otra forma

#Creando una distribución normal

x <- seq(-4, 4, length=100)

y <- dnorm(x)

plot(x,y,type="l",lwd=2,axes= TRUE,xlab ="z",ylab ="Desnsity")

xv <- seq(-2, 2)

px <- dnorm(xv)

polygon(c(xv, rev(xv)), c(px, rep(0, length(px))),

col = adjustcolor('green', alpha=0.3), border = NA)

#Creando la distribución t

curve(dt(x, df=6), from=-4, to=4,

main = 't Distribution',

ylab = 'Density',xlab ="t",

lwd = 2,

col = 'blue')

curve(dt(x, df=10), from=-4, to=4, col='red',lwd = 3, add=TRUE)

curve(dt(x, df=30), from=-4, to=4, col='green',lwd = 4 ,add=TRUE)

legend(-4, .3, legend=c("df=6", "df=10", "df=30"),

col=c("blue", "red", "green"), lty=1, cex=0.8)

#Creando Distribución chi2

curve(dchisq(x, df = 6), from = 0, to = 40,

main = 'Chi-Square Distribution (df =)',

ylab = 'Density',

lwd = 2)

xc <- seq(10, 40)#crea vector

pc <- dchisq(xc, df = 6)#crea densidad

#crea densidad vector xc

polygon(c(xc, rev(xc)), c(pc, rep(0, length(pc))),

col = adjustcolor('red', alpha=0.3), border = NA)

curve(dchisq(x, df = 12), from = 0, to = 40,col = 'blue',add=TRUE)

curve(dchisq(x, df = 30), from = 0, to = 40,col = 'green',add=TRUE)


legend(30, 0.10, legend=c("df=6", "df=12", "df=30"),

col=c("black", "red", "green"), lty=1, cex=0.8)

#Creando distribución F

curve(df(x, df1=10, df2=60), from=0, to=5, main="Distribucion F")

F.critico=2.061

xp = seq(0, 5, length = 100)

y=df(x=xp,df1=10,df2=60)

polygon(c(F.critico, F.critico, xp[xp>F.critico], max(xp)),

c(0, df(F.critico, df1=10, df2=60), y[xp>F.critico], 0),

col = "blue")

curve(df(x, df1=10, df2=45), from=0, to=5,col='red' ,add=TRUE)

curve(df(x, df1=10, df2=30), from=0, to=5,col='green' ,add=TRUE)

legend(4, 0.8, legend=c("df=10,60", "df=10,45", "df=10,30"),

col=c("black", "red", "green"), lty=1, cex=0.5)

curve(df(x, df1=10, df2=100), from=0, to=5,col='brown' ,add=TRUE)

You might also like