Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in plotcc.R #3

Open
reza-bagheri opened this issue Dec 15, 2018 · 1 comment
Open

A bug in plotcc.R #3

reza-bagheri opened this issue Dec 15, 2018 · 1 comment

Comments

@reza-bagheri
Copy link

In plotcc.R file in the folder R/chapter5/, you have used:

contour(gridvalsX,gridvalsY,matrix(Probs,nrow=dim(Xv)[[1]],ncol=dim(Xv)[[2]],byrow=TRUE),add=TRUE)

However, it should be:

contour(gridvalsX,gridvalsY,matrix(Probs,nrow=dim(Xv)[[2]],ncol=dim(Xv)[[1]],byrow=TRUE),add=TRUE)

That is because in the meshgrid output, the rows of the output array X are copies of the vector gridvalsX, so the length of gridvalsX is equal to the number of columns in mesh$X which is dim(Xv)[[2]], and length of gridvalsY is equal to the number of rows in mesh$X which is dim(Xv)[[1]]. The code runs since both gridvalsX and gridvalsY have the same dimension, however, if you make them different, you get an error.

@reza-bagheri
Copy link
Author

There is also a bug in the line that calculates the Gaussian:

const = -log(2*pi) - log(det(tempc))

In fact it should be the square root of the determinant of the covariance matrix, so it sholud be:

const = -log(2*pi) - log(sqrt(det(tempc)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant