# source("C:\\Users\\USER\\cnaber\\Disciplinas\\Pos\\1_semestre_2021\\Regressao MI 406\\programas\\Distribuicao Normal multivariada Pos Reg MI406 1S 2021.r") # limpar todas as variáveis rm(list = ls(all.names = TRUE)) set.seed(4142) library(MASS) file.save <- "C:\\Users\\USER\\cnaber\\Disciplinas\\Pos\\1_semestre_2021\\Regressao MI 406\\aulas\\DNM\\" # Surface of the densities corre<-c(0,0,-0.9,0.9) # lets first simulate a bivariate normal sample bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[1], corre[1], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNMS.pdf", height=15, width=15) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNM.pdf") #dev.new(width=20, height=5) #par(mar=c(0.01,0.01,0.01,0.01)) pdf(paste(file.save,sep="","DistNM1.pdf")) par(mfrow=c(2,2)) par(mar = c(1, 1, 1, 1)) #par(mar=c(1.0, 1.0, 0.1, 0.1)) #par(mai=c(0.1, 0.1, 0.1, 0.1)) # now plot your results persp(bivn.kde, phi = 45, theta = 30, shade = .1,main=paste("correlação = ",0),col="lightblue",ticktype="detailed",cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="",zlab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(9, corre[2], corre[2], 9), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results persp(bivn.kde, phi = 45, theta = 30, shade = .1,main=paste("correlação = ",0, ", variâncias = ",9),col="lightblue",ticktype="detailed",cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="",zlab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[3], corre[3], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results persp(bivn.kde, phi = 45, theta = 30, shade = .1,main=paste("correlação = ",corre[3]),col="lightblue",ticktype="detailed",cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="",zlab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[4], corre[4], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results persp(bivn.kde, phi = 45, theta = 30, shade = .1,main=paste("correlação = ",corre[4]),col="lightblue",ticktype="detailed",cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="",zlab="") #dev.off() dev.off() # Countor plots corre<-c(0,0,-0.9,0.9) #par(mfrow=c(2,2)) # lets first simulate a bivariate normal sample bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[1], corre[1], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNMC.pdf", height=15, width=15) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNM.pdf") resetPar <- function() { dev.new() op <- par(no.readonly = TRUE) dev.off() op } #dev.new(width=20, height=5) #par(mar=c(0.01,0.01,0.01,0.01)) pdf(paste(file.save,sep="","DistNM2.pdf")) par(resetPar()) par(mfrow=c(2,2)) #par(mar = c(0, 0, 0, 0)) # now plot your results contour(bivn.kde,main=paste("correlação = ",0),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(9, corre[2], corre[2], 9), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results contour(bivn.kde,main=paste("correlação = ",0),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[3], corre[3], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results contour(bivn.kde,main=paste("correlação = ",corre[3]),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[4], corre[4], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results contour(bivn.kde, main=paste("correlação = ",corre[4]),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") #dev.off() dev.off() # zoom # Countor plots corre<-c(0,0,-0.9,0.9) #par(mfrow=c(2,2)) pdf(paste(file.save,sep="","DistNM01.pdf")) par(mfrow=c(1,1)) # lets first simulate a bivariate normal sample bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[1], corre[1], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNMC.pdf", height=15, width=15) #pdf("E://windows//Unicamp//Disciplinas//2_semestre_2013//Inferencia Bayesiana//Aulas//Inferencia Bayesiana em Modelos Lineares//AllNM.pdf") resetPar <- function() { dev.new() op <- par(no.readonly = TRUE) dev.off() op } #dev.new(width=20, height=5) #par(mar=c(0.01,0.01,0.01,0.01)) #par(resetPar()) #par(mfrow=c(2,2)) #par(mar = c(0, 0, 0, 0)) # now plot your results contour(bivn.kde,main=paste("correlação = ",0),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") dev.off() bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(9, corre[2], corre[2], 9), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) pdf(paste(file.save,sep="","DistNM02.pdf")) # now plot your results contour(bivn.kde,main=paste("correlação = ",0),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") dev.off() bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[3], corre[3], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results pdf(paste(file.save,sep="","DistNM03.pdf")) contour(bivn.kde,main=paste("correlação = ",corre[3]),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") dev.off() bivn <- mvrnorm(10000, mu = c(0, 0), Sigma = matrix(c(1, corre[4], corre[4], 1), 2)) # now we do a kernel density estimate bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50) # now plot your results pdf(paste(file.save,sep="","DistNM04.pdf")) contour(bivn.kde, main=paste("correlação = ",corre[4]),cex.axis=1.3,cex.lab=1.3,cex.main=1.3,xlab="",ylab="") dev.off() #dev.off()