####a)
#### Generador multiplicativo propuesto
a<-7^5
c<-0
m<-2^31-1
initRANDC(7880,a,c,m)
u <- RANDCN(10000)
library(rgl)
y <- matrix(u, ncol = 3, byrow = TRUE)
## Warning in matrix(u, ncol = 3, byrow = TRUE): la longitud de los datos
## [10000] no es un submúltiplo o múltiplo del número de filas [3334] en la
## matriz
plot3d(y)
#### Generador Randu IBM
a<-65539
c<-0
m<-2^31-1
initRANDC(7880,a,c,m)
u <- RANDCN(10000)
library(rgl)
y <- matrix(u, ncol = 3, byrow = TRUE)
## Warning in matrix(u, ncol = 3, byrow = TRUE): la longitud de los datos
## [10000] no es un submúltiplo o múltiplo del número de filas [3334] en la
## matriz
plot3d(y)
No tenemos los mismos problemas con el generador aleatorio multiplicativo propuesto, los datos parecén más aleatorios.
#b)
nsim <-500
estadistico <- numeric(nsim)
pvalor <- numeric(nsim)
initRANDC(7880,a,c,m)
for(isim in 1:nsim){
u <- RANDCN(n)
tmp <- Box.test(u, lag = 10, type = "Ljung")
estadistico[isim]<-tmp$statistic
pvalor[isim] <- tmp$p.value
}
initRANDC(7880,a,c,m)
x <- RANDCN(20000)
# Histograma
hist(estadistico, freq=FALSE,ylim=c(0,0.1),xlab="EstadÃstico",ylab="Densidad",main=" ")
lines(density(estadistico),lwd=2,col="red")
curve(dchisq(x,10), add=TRUE,col="blue")
legend("topright",c("Densidad estimada","Densidad chi-cuadrado"), lty=c(1,1),col=c('red','blue'), box.lty=0)
# Histograma
hist(pvalor, freq=FALSE,xlab="p-valor",ylab="Densidad",main=" ")
curve(dunif(x,0,1), add=TRUE,col="blue")
legend("topright",c("Densidad Uniforme(0,1)"), lty=1,col='blue', box.lty=0)