Construction of two-dimensional Gaussians in R

I have two classes: C1 and C2, both of which are described by two-dimensional Gaussians with means in (0,0) and (1,3) and covariances I and 2I. Priors C1 and C2 are equal to 0.4 and 0.6, respectively.

I need to plot 10 points C1 and 15 points C2 on a scatter plot in R for later purposes of calculating some classification boundaries, so this is not a crucial part of the problem, I just need to know how to do this so that I can start.

I tried looking for documentation online, but it doesn't seem to help.

+4
source share
3 answers

try it

library('MASS') sz_1<-10; sz_2<-15; df<-rbind(data.frame(mvrnorm(n=sz_1,mu=c(0,0),Sigma=diag(2))),data.frame(mvrnorm(n=sz_2,mu=c(1,3),Sigma=2*diag(2)))); plot(df,xlab="x-value",ylab="y-value",col="purple",main="scatter-plot of mixed gaussians"); 
+3
source
 require(mvtnorm) l=3 sigma <- matrix(c(l,2,2,2*l), ncol=2) C2 <- rmvnorm(n=15, mean=c(1,3), sigma=sigma) C1 <- rmvnorm(n=10, mean=c(0,0), sigma=sigma) plot(C1, xlim=range( c(C1[,1],C2[,1]) ) , ylim=range( c(C1[,2],C2[,2]) ) , col="red") points(C2, col="blue") 

enter image description here

+1
source

The dmnorm function you found there will generate a 2nd Gaussian interface, but still there is a problem with two separate classes. To do this, use your priorities 0.4 and 0.6. You can use Bernoulli or runif () <p to select the class of each point created sequentially. That should do it.

0
source

All Articles