Change values in logistic regression

I need to change the values of the variables that are taken as reference when doing the logistic regression.
I made this reprex to show what I need

# A tibble: 15 × 4
   test1 test2 test3 test4
   <fct> <chr> <chr> <chr>
 1 No    car   red   Up   
 2 Yes   bike  pink  Up   
 3 Yes   bike  blue  Down 
 4 No    car   red   Up   
 5 Yes   car   blue  Up   
 6 No    bike  red   Up   
 7 Yes   bike  pink  Down 
 8 Yes   car   pink  Down 
 9 No    bike  pink  Down 
10 No    bike  red   Down 
11 Yes   bike  pink  Up   
12 Yes   car   blue  Down 
13 Yes   bike  red   Up   
14 Yes   bike  red   Down 
15 No    bike  red   Up
metodo_prueba <- glm(formula = test1 ~   
                 test2 +
                 test3 +
               data = prueba,
               family = binomial(link = "logit"))


I only will show the coeficients because that is what It matters for me now:

              Estimate Std. Error z value Pr(>|z|)
(Intercept)  1.923e+01  3.705e+03   0.005    0.996
test2car    -9.163e-01  1.621e+00  -0.565    0.572
test3pink   -1.762e+01  3.705e+03  -0.005    0.996
test3red    -1.992e+01  3.705e+03  -0.005    0.996
test4Up      2.803e-15  1.443e+00   0.000    1.000

How can I make the coefficients relative to the other values? For example, test2bike instead of test2car. Test4Down instead of test4Up.


I think this would be a good resource for you

how would it work in this case?

Here is a simple example, not even using contrasts but simply factor levels explicity.
when you have char types, they will be auto interpreted as factors with default levels based on alphabetic orderings; Here is an example where in the second model I relevel test2 to put cars level before bike level and you can see that this changes the categories and coefficients to accomodate

prueba <- tibble::tribble(
   ~test1,  ~test2,  ~test3,  ~test4,
     "No",   "car",   "red",    "Up",
    "Yes",  "bike",  "pink",    "Up",
    "Yes",  "bike",  "blue",  "Down",
     "No",   "car",   "red",    "Up",
    "Yes",   "car",  "blue",    "Up",
     "No",  "bike",   "red",    "Up",
    "Yes",  "bike",  "pink",  "Down",
    "Yes",   "car",  "pink",  "Down",
     "No",  "bike",  "pink",  "Down",
     "No",  "bike",   "red",  "Down",
    "Yes",  "bike",  "pink",    "Up",
    "Yes",   "car",  "blue",  "Down",
    "Yes",  "bike",   "red",    "Up",
    "Yes",  "bike",   "red",  "Down",
     "No",  "bike",   "red",    "Up"
  ) |> mutate(test1=factor(test1))

metodo_prueba_1 <- glm(formula = test1 ~   
                         test2 +
                         test3 +
                       data = prueba,
                       family = binomial(link = "logit"))

metodo_prueba_2 <- glm(formula = test1 ~   
                         test2 +
                         test3 +
                       data = prueba |> mutate(test2=factor(test2) |>
                       family = binomial(link = "logit"))

sm1 <- summary(metodo_prueba_1)
sm2 <- summary(metodo_prueba_2)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.