Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Estadística Computacional.
Practica Calificada Nº 4
Profesor : Frida Coaquira
Duración : 110 minutos
INDICACIONES
La evaluación es estrictamente personal
En la calificación se considerará el orden y la limpieza.
Todos los cálculos de ser necesario deben aproximarlos a tres decimales.
Presente todo el procedimiento necesario (Código y salida) interprete la respuesta
Y X1 X2 X3 X4
79.3 5.5 31 10 8
200.1 2.5 55 8 6
163.2 8 67 12 9
200.1 3 50 7 16
146 3 38 8 15
177.7 2.9 71 12 17
30.9 8 30 12 8
291.9 9 56 5 10
160 4 42 8 4
339.4 6.5 73 5 16
159.6 5.5 60 11 7
86.3 5 44 12 12
237.5 6 50 6 6
107.2 5 39 10 4
155 3.5 55 10 4
291.4 8 70 6 14
100.2 6 40 11 6
135.8 4 50 11 8
223.3 7.5 62 9 13
195 7 59 9 11
a) (3 puntos) Ajuste una ecuación de regresión lineal considerando todas las variables
predictoras. Obtenga el modelo final que contenga solo variables significativas. α =
0.04. interprete los coeficientes.
b) (3 puntos) Estime los coeficientes del modelo de regresión en base a los errores
(B=50 , 100) . Interprete los coeficientes.
DATA_PC4=as.matrix(DATA_PC4)
boot.res=function(datos,B,Y)
{
datos=as.matrix(datos)
n=nrow(datos)
c=ncol(datos)
betas=matrix(0,B,c)
resid=lm(datos[,Y]~datos[,-Y])$res
for (i in 1:B)
{
betas[i,]=lm(datos[,Y]+sample(resid,n,T)~datos[,-Y])$coe
}
bootbetas=apply(betas,2,mean)
eebotbet=apply(betas,2,sd)
return(list(bootb=bootbetas,eebootb=eebotbet))
}
boot.res(DATA_PC4,50,1)
boot.res(DATA_PC4,100,1)
Resultado Boosstrap
ic.me.boot.obser=function(datos,B,Y,nivel)
{
datos=as.matrix(datos)
alfa=1-0.01*nivel
n=dim(datos)[1]
c=ncol(datos)
coefi=lm(datos[,Y]~datos[,-Y])$coe
betas=matrix(0,B,c)
eebetas=matrix(0,B,c)
pivot=matrix(0,B,c)
for (i in 1:B)
{
indices=sample(1:n,n,T)
betas[i,]=lm(datos[indices,Y]~datos[indices,-Y])$coe
eebetas[i,]=summary(lm(datos[indices,Y]~datos[indices,-Y]))$coe[,2]
pivot[i,]=(betas[i,]-coefi)/eebetas[i,]
}
eebotbet=apply(betas,2,sd)
t1=apply(pivot,2,quantile,alfa/2)
t2=apply(pivot,2,quantile,1-alfa/2)
LI=coefi+t1*eebotbet
LS=coefi+t2*eebotbet
limites=cbind(LI,LS)
return(list(limites=limites))
}
ic.me.boot.obser(datos=DATA_PC4,B=50,Y=1,nivel=95)
ic.me.boot.obser(datos=DATA_PC4,B=100,Y=1,nivel=95)
Interpretación: Los intervalos de confianza para los coeficientes son estables para
el Boostrap 50 y 100 no existiendo una variación significativa.
N° X Y N° X Y N° X Y
1.0 125.5 94.2 8 123.2 96.4 15 126.9 95.8
2.0 125.8 94.5 9 124.2 96.8 16 127.3 96.9
3.0 126.1 94.8 10 123.8 97.1 17 127.7 96.6
4.0 121.9 95.1 11 120.9 97.4 18 128.1 93.2
5.0 122.2 92.5 12 121.2 97.7 19 125.0 93.6
6.0 122.5 92.1 13 121.6 98.1 20 124.6 94.0
7.0 122.9 93.5 14 122.9 98.4 21 126.2 95.5
DATA_PC4_2=as.matrix(DATA_PC4_2)
TG <- function(X,Y) {
coeficiente <- (mean(X)^2 - 1)/(mean(Y)^2 + 2)
coeficiente
}
TG(DATA_PC4_2[,1],DATA_PC4_2[,2])
jack.TG=function(datos,x,y)
{
n=nrow(datos)
esjack=rep(0,n)
ecord=TG(datos[,x],datos[,y])
for (i in 1:n)
{
esjack[i]=TG(datos[-i,x],datos[-i,y])
}
estimjackcor=mean(esjack)
sesgojack=(n-1)*(estimjackcor- ecord)
eejack= ((n-1)/sqrt (n))*sd(esjack)
return(list(estimjackcor=estimjackcor, sesgo=
sesgojack ,eejack=eejack))
}
jack.TG(DATA_PC4_2,1,2)
b) (6 puntos) Haga una función para estimar: CV(Y) , Var(X) y sus errores
usando el algoritmo Jacknife
DATA_PC4_2=as.matrix(DATA_PC4_2)
CV<- function(Y) {
coeficiente <- sd(Y)/mean(Y)
coeficiente
}
jack.CV=function(datos,Y)
{
n=length(datos)
esjack=rep(0,n)
for (i in 1:n)
{
esjack[i]=CV(datos[-i,Y])
}
estimjack=mean(esjack)
return(estimjack=estimjack)
}
jack.CV(DATA_PC4_2,2)
jack.VAR=function(datos,Y)
{
n=length(datos)
esjack=rep(0,n)
for (i in 1:n)
{
esjack[i]=var(datos[-i,Y])
}
estimjack=mean(esjack)
return(estimjack=estimjack)
}
jack.VAR(DATA_PC4_2,1)