I have the following R code
ldf <- function(x, prior, mu, covar)
{
x <- matrix(as.numeric(diabetes), ncol=1)
log(lda.res$prior) - (0.5*t(lda.res$mean)%*%solve(cov_all)%*%lda.res$mean) + (t(x)%*%solve(covar)%*%mu)
}
I understand that the code is a function which will calculate the linear discriminant function.
However, I am unsure of what the following code is doing. It follows directly after the code above.
I know it is calculating the linear discriminant function for a patient but i'm not sure what each line means.
id <- 1
dfs <- rep(0, G)
for(g in 1:G)
{
dfs[g] <- ldf(diabetes[id,2:4], lda.res$prior[g], lda.res$mean[g,], cov_all)
}
dfs
levels(diabetes$class)[dfs == max(dfs)]
Thank you in advance for any help!