Emit the discriminant function constant - linear discriminant analysis [R]

3

How to emit the constant of the discriminant function (or constants, if multiple discriminant analysis)? It follows the dput to aid in the response.

structure(list(REAÇÃO = structure(c(0, 1, 0, 0, 1, 0, 1, 1, 
0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 
1, 0, 1, 1, 0, 1, 1), format.spss = "F11.0"), IDADE = structure(c(22, 
38, 36, 58, 37, 31, 32, 54, 60, 34, 45, 27, 30, 20, 30, 30, 22, 
26, 19, 18, 22, 23, 24, 50, 20, 47, 34, 31, 43, 35, 23, 34, 51, 
63, 22, 29), format.spss = "F11.0"), ESCOLARIDADE = structure(c(6, 
12, 12, 8, 12, 12, 10, 12, 8, 12, 12, 12, 8, 4, 8, 8, 12, 8, 
9, 4, 12, 6, 12, 12, 12, 12, 12, 12, 12, 8, 8, 12, 16, 12, 12, 
12), format.spss = "F11.0"), SEXO = structure(c(1, 1, 0, 0, 1, 
0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 
0, 1, 0, 1, 0, 0, 0, 1, 1, 1), format.spss = "F11.0")), .Names = c("REAÇÃO", 
"IDADE", "ESCOLARIDADE", "SEXO"), row.names = c(NA, -36L), class = "data.frame")

Where: REAÇÃO is the dependent variable and the other independent.

Since it is simple discriminant analysis (two groups), it will only have one constant for the unique function of the model. Of course, this constant has the value of -4.438 . Preferably, I request that it be obtained with a simple function to execute.

    
asked by anonymous 16.08.2018 / 03:58

2 answers

3

Browsing the OS, I found this topic where a constant is calculated based on the mathematical formula. The code below will return you the value of 4.437946 , which differs from the value you yourself said by the signal.

library(MASS)
fit <- lda(REAÇÃO ~ ., data = dados)
fit # show results
plot(fit)
groupmean <- (fit$prior%*%fit$means)
constant <- (groupmean%*%fit$scaling)

I may be wrong, but because of the structure you provided and the answers to the topic I mentioned, you found this constant through SPSS , and the reference value of the REAÇÃO variable it uses is the inverse of what the R uses. If you want the value to beat,

dados$REAÇÃO <- as.factor(dados$REAÇÃO)
dados2 <- within(dados, REAÇÃO <- relevel(REAÇÃO, ref = 2))
fit2 <- lda(REAÇÃO ~ ., data = dados2)
fit2 # show results
plot(fit2)
groupmean2 <- (fit2$prior%*%fit2$means)
constant2 <- (groupmean2%*%fit2$scaling)
    
04.09.2018 / 15:14
1

After performing the discriminant analysis with the package MASS , the constant can be obtained. The expression is:

groupmean<-(model$prior%*%model$means)
constant<-(groupmean%*%model$scaling)
constant

Where model is the discriminant model. For example:

model<-lda(y~x1+x2+xn,data=mydata)
model

Attention only to the sign of the constant.

Any other (useful) answer that complements this will earn the reward.

    
04.09.2018 / 04:21