@@ -217,16 +217,40 @@ mlClassificationLogisticMultinomial <- function(jaspResults, dataset, options, .
217
217
table [[" upper" ]] <- coefs [, " upper" ]
218
218
}
219
219
if (options [[" formula" ]]) { # TODO FOR MULTINOMIAL
220
- one_cat <- levels(factor (classificationResult [[" train" ]][[options [[" target" ]]]]))[2 ]
221
- if (options [[" intercept" ]]) {
222
- regform <- paste0(" logit(p<sub>" , options [[" target" ]], " = " , one_cat , " </sub>) = " , round(as.numeric(coefs [, 1 ])[1 ], 3 ))
223
- start <- 2
220
+ if (classificationResult [[" family" ]] == " binomial" ) {
221
+ one_cat <- levels(factor (classificationResult [[" train" ]][[options [[" target" ]]]]))[2 ]
222
+ if (options [[" intercept" ]]) {
223
+ regform <- paste0(" logit(p<sub>" , options [[" target" ]], " = " , one_cat , " </sub>) = " , round(as.numeric(coefs [, 1 ])[1 ], 3 ))
224
+ start <- 2
225
+ } else {
226
+ regform <- paste0(" logit(p<sub>" , options [[" target" ]], " = " , one_cat , " </sub>) = " )
227
+ start <- 1
228
+ }
229
+ for (i in start : nrow(coefs )) {
230
+ regform <- paste0(regform , if (round(as.numeric(coefs [, 1 ])[i ], 3 ) < 0 ) " - " else " + " , abs(round(as.numeric(coefs [, 1 ])[i ], 3 )), " x " , rownames(coefs )[i ])
231
+ }
224
232
} else {
225
- regform <- paste0(" logit(p<sub>" , options [[" target" ]], " = " , one_cat , " </sub>) = " )
226
- start <- 1
227
- }
228
- for (i in start : nrow(coefs )) {
229
- regform <- paste0(regform , if (round(as.numeric(coefs [, 1 ])[i ], 3 ) < 0 ) " - " else " + " , abs(round(as.numeric(coefs [, 1 ])[i ], 3 )), " x " , rownames(coefs )[i ])
233
+ regform <- NULL
234
+ nlevs <- nlevels(classificationResult [[" train" ]][[options [[" target" ]]]])
235
+ baseline_cat <- levels(classificationResult [[" train" ]][[options [[" target" ]]]])[nlevs ]
236
+ for (i in seq_len(nlevs - 1 )) {
237
+ current_cat <- levels(classificationResult [[" train" ]][[options [[" target" ]]]])[i ]
238
+ if (options [[" intercept" ]]) {
239
+ part <- paste0(" log(p<sub>" , options [[" target" ]], " = " , current_cat , " </sub> / p<sub>" , options [[" target" ]], " = " , baseline_cat , " </sub>) = " , round(as.numeric(coefs [, 1 ])[i ], 3 ))
240
+ start <- nlevs - 1 + i
241
+ } else {
242
+ part <- paste0(" log(p<sub>" , options [[" target" ]], " = " , current_cat , " </sub> / p<sub>" , options [[" target" ]], " = " , baseline_cat , " </sub>) = " )
243
+ start <- i
244
+ }
245
+ for (j in seq(start , nrow(coefs ), by = nlevs - 1 )) {
246
+ part <- paste0(part , if (round(as.numeric(coefs [, 1 ])[j ], 3 ) < 0 ) " - " else " + " , abs(round(as.numeric(coefs [, 1 ])[j ], 3 )), " x " , strsplit(rownames(coefs )[j ], " : " )[[1 ]][1 ])
247
+ }
248
+ if (i == 1 ) {
249
+ regform <- paste0(regform , part , " \n\n " )
250
+ } else {
251
+ regform <- paste0(regform , part )
252
+ }
253
+ }
230
254
}
231
255
formula <- createJaspHtml(gettextf(" <b>Regression equation:</b>\n %1$s" , regform ), " p" )
232
256
formula $ position <- position + 1
0 commit comments