barplot(joint.prob, density=40, main="In a fair society, differencesin people's standard of living should be small",xlab="", ylab="proportions",ylim=c(0,0.30),legend=rownames(joint.prob))
Conditional Distribution and Mean
and
Trials with Multiple Categories: Multinomial Distribution
dmultinom(c(0,1,11),prob=c(0.20, 0.30, 0.50))
[1] 0.001757812
Independence
joint.prob <-prop.table(fairsociety) # derives proportion table# from a frequency tablecond.prob1 <-prop.table(fairsociety, 1) # cond. prop. within rowscond.prob2 <-prop.table(fairsociety, 2) # cond. prop. within columnsbarplot(cond.prob2, density=40, main="In a fair society, differencesin people's standard of living should be small",xlab="", ylab="conditional proportions",ylim=c(0,1))abline(h=0.5, col="blue")
Markov Chains
Correlation
Correlation describes the strength of a linear association!
weightedCorr(x, y, weights=probabilities, method="polyserial")
[1] 0.700897
probabilities <-c(0.15,0.00,0.15,0.00,0.40,0.00,0.15,0.00,0.15)weightedCorr(x, y, weights=probabilities, method="polyserial")
[1] -3.330669e-16
Bivariate Normal Distribution
library(mvtnorm); library(plot3D)x <- (-40:40)/10; y <- xxy <-mesh(x,y) # function that generates a full 2-D or 3-D gridx0 <-as.vector(xy$x); y0 <-as.vector(xy$y); z0 <-cbind(x0, y0)# parameter-values of the 2-dim. normal distribution:mean <-c(0,0) # mean vectorsigma <-matrix(c(1,0.7,0.7,1), ncol=2) # covariance matrix# pdf of a multivariate normal distribution:z1 <-dmvnorm(z0, mean, sigma) # pdf of multivariate normalz =matrix(z1, ncol =length(x))persp3D(z = z, x = x, y = y, theta =-30, phi =30, colvar = z, col="steelblue",shade =0.5, main="cor=0.7")
library(fMultivar); library(graphics)x <- (-40:40)/10; X <-grid2d(x)z <-dnorm2d(X$x, X$y, rho =-0.8)X <-list(x = x, y = x, z =matrix(z, ncol =length(x)))# Perspective Density Plot:persp(X, theta =-30, phi =25, expand =0.5, col ="lightblue", ltheta =120, shade =0.15, ticktype ="detailed", xlab ="x", ylab ="y", zlab =" ")
Simulation:
Conditional variance \(Y|X\)
x<-rnorm(1000,70, 10) # simulate n=1000 from normal with mean=70 and standard dev=10y<-rnorm(1000,70+0.6*(x-70),6) #E(Y|x)=70+0.6*(x-70)plot(x,y)
This idea can be extended to the multivariate normal distribution.