Good morning, I have a problem plotting. In the last 10 lines of the syntax I try to create a plot for the bias but I get the following error: "Error in xy.coords (x, y, xlabel, ylabel, log): 'x' and 'y' lengths differ" It seems that there is an error with the coordinates of the graph and I do not know how to solve it
I would appreciate any help.
Thanks.
# Numero de Simulaciones
M<-10000
# Tamaños de Muestra
n<-c(100,500,1000)
# Parametros
S<-0.9
C<-0.9
# Matriz de resultados
T<-matrix(0,M,9)
colnames(T)<-c("Xbar.100.P1","Xbar.100.P2","Xbar.100.P3",
"Xbar.500.P1","Xbar.500.P2","Xbar.500.P3",
"Xbar.1000.P1","Xbar.1000.P2","Xbar.1000.P3")
# Estudio de SimulaciOn
set.seed(1000)
for(h in 1:3){
for(j in 1:M){
P1<- rbinom(1,n[h],(0.01*S) + (1−0.01)*(1−C))
P2<- rbinom(1,n[h],(0.05*S) + (1−0.05)*(1−C))
P3<- rbinom(1,n[h],(0.1*S) + (1−0.1)*(1−C))
a<-(3*(h-1)+1)
b<- 3*h
T[j,a:b]<-c(mean(P1)/n[h],mean(P2)/n[h],mean(P3)/n[h])
}
}
# Analisis de Resultados
est<-rep(c("Media"),times=1)
dis<-rep(c("P1","P2","P3"),times=3)
tam<-rep(n,each=3)
sesgo<-colMeans(T)
a1<-c(0.01,0.01,0.01,0.05,0.05,0.05,0.1,0.1,0.1)
a2<-rbind(x)
sesgo_f <- sesgo-a1
variancia<-diag(var(T))
ecm<-variancia+sesgo^2
# Tabla Error Cuadratico Medio
res<-rbind(
matrix(ecm[dis=="P1"],3,1,byrow=T),
matrix(ecm[dis=="P2"],3,1,byrow=T),
matrix(ecm[dis=="P3"],3,1,byrow=T)
)
res<-cbind(
rep(n,1),
res
)
colnames(res)<-c("T. de Muestra","Media")
rownames(res)<-rep(c("P1","P2","P3"),each=3)
round(res,4)
ecm
# Tabla Sesgo
res<-rbind(
matrix(sesgo_f[dis=="P1"],3,1,byrow=T),
matrix(sesgo_f[dis=="P2"],3,1,byrow=T),
matrix(sesgo_f[dis=="P3"],3,1,byrow=T)
)
res<-cbind(
rep(n,2),
res
)
colnames(res)<-c("T. de Muestra","Media")
rownames(res)<-rep(c("P1","P2","P3"),each=3)
round(res,4)
sesgo_f
# Gr�fico - Error Cuadr�tico Medio
#par(mfrow=c(1,2))
plot(n,ecm[(dis=="P1")&(est=="Media")],ylim=c(0,0.04),
type="l",col=1,lty=1,lwd=2,
main="Error Cuadratico Medio",
xlab="Tamaño de Muestra",
ylab="Error Cuadratico Medio")
lines(n,ecm[(dis=="P2")&(est=="Media")],
col=2,lty=2,lwd=2)
lines(n,ecm[(dis=="P3")&(est=="Media")],
col=3,lty=4,lwd=2)
legend("topright",c("P1","P2","P3"),col=c(1,2,3),lty=c(1,2,4),lwd=2)
# Grafico - Sesgo
#est<-rep(c("Media"),times=1)
#dis<-rep(c("P1","P2","P3"),times=3)
#tam<-rep(n,each=3)
plot(n,sesgo_f[(dis=="P1")&(est=="Media")],ylim=c(0,0.04),
type="l",col=1,lty=1,lwd=2,
main="Error Cuadratico Medio",
xlab="Tamaño de Muestra",
ylab="Error Cuadratico Medio")
lines(n,sesgo_f[(dis=="P2")&(est=="Media")],
col=2,lty=2,lwd=2)
lines(n,sesgo_f[(dis=="P3")&(est=="Media")],
col=3,lty=4,lwd=2)
legend("topright",c("P1","P2","P3"),col=c(1,2,3),lty=c(1,2,4),lwd=2)