Is there any way to fit a `glm()` so that all levels are included (i.e. no reference level)?

前端 未结 2 574
说谎
说谎 2021-01-03 17:30

Consider the code:

x <- read.table(\"http://data.princeton.edu/wws509/datasets/cuse.dat\",
                header=TRUE)[,1:2]

fit <- glm(education ~ a         


        
2条回答
  •  日久生厌
    2021-01-03 17:31

    You'll want to use the model.matrix function to convert the factors in the age variable to binary variables.

    See this answer.

    EDIT: Here is an example:

    x <- read.table("http://data.princeton.edu/wws509/datasets/cuse.dat",
                    header=TRUE)[,1:2]
    binary_variables <- model.matrix(~ x$age -1, x)
    fit <- glm(x$education ~ binary_variables, family="binomial")
    summary(fit)
    

提交回复
热议问题