insight
insight copied to clipboard
get_modelmatrix for nlme doesn't fully incorporate all info
Related to easystats/parameters#706
library(nlme)
library(effectsize)
data("mtcars")
mtcars$cyl <- factor(mtcars$cyl)
fm1 <- lme(mpg ~ cyl, mtcars, random = ~ 1| gear,
contrasts = list("cyl" = contr.sum))
insight::get_modelmatrix(fm1)
#> (Intercept) cyl6 cyl8
#> Mazda RX4 1 1 0
#> Mazda RX4 Wag 1 1 0
#> Datsun 710 1 0 0
#> Hornet 4 Drive 1 1 0
#> Hornet Sportabout 1 0 1
#> Valiant 1 1 0
#> Duster 360 1 0 1
#> Merc 240D 1 0 0
#> Merc 230 1 0 0
#> Merc 280 1 1 0
#> Merc 280C 1 1 0
#> Merc 450SE 1 0 1
#> Merc 450SL 1 0 1
#> Merc 450SLC 1 0 1
#> Cadillac Fleetwood 1 0 1
#> Lincoln Continental 1 0 1
#> Chrysler Imperial 1 0 1
#> Fiat 128 1 0 0
#> Honda Civic 1 0 0
#> Toyota Corolla 1 0 0
#> Toyota Corona 1 0 0
#> Dodge Challenger 1 0 1
#> AMC Javelin 1 0 1
#> Camaro Z28 1 0 1
#> Pontiac Firebird 1 0 1
#> Fiat X1-9 1 0 0
#> Porsche 914-2 1 0 0
#> Lotus Europa 1 0 0
#> Ford Pantera L 1 0 1
#> Ferrari Dino 1 1 0
#> Maserati Bora 1 0 1
#> Volvo 142E 1 0 0
#> attr(,"assign")
#> [1] 0 1 1
#> attr(,"contrasts")
#> attr(,"contrasts")$cyl
#> [1] "contr.treatment"
expected behavior:
fm2 <- lm(mpg ~ cyl, mtcars,
contrasts = list("cyl" = contr.sum))
insight::get_modelmatrix(fm2)
#> (Intercept) cyl1 cyl2
#> Mazda RX4 1 0 1
#> Mazda RX4 Wag 1 0 1
#> Datsun 710 1 1 0
#> Hornet 4 Drive 1 0 1
#> Hornet Sportabout 1 -1 -1
#> Valiant 1 0 1
#> Duster 360 1 -1 -1
#> Merc 240D 1 1 0
#> Merc 230 1 1 0
#> Merc 280 1 0 1
#> Merc 280C 1 0 1
#> Merc 450SE 1 -1 -1
#> Merc 450SL 1 -1 -1
#> Merc 450SLC 1 -1 -1
#> Cadillac Fleetwood 1 -1 -1
#> Lincoln Continental 1 -1 -1
#> Chrysler Imperial 1 -1 -1
#> Fiat 128 1 1 0
#> Honda Civic 1 1 0
#> Toyota Corolla 1 1 0
#> Toyota Corona 1 1 0
#> Dodge Challenger 1 -1 -1
#> AMC Javelin 1 -1 -1
#> Camaro Z28 1 -1 -1
#> Pontiac Firebird 1 -1 -1
#> Fiat X1-9 1 1 0
#> Porsche 914-2 1 1 0
#> Lotus Europa 1 1 0
#> Ford Pantera L 1 -1 -1
#> Ferrari Dino 1 0 1
#> Maserati Bora 1 -1 -1
#> Volvo 142E 1 1 0
#> attr(,"assign")
#> [1] 0 1 1
#> attr(,"contrasts")
#> attr(,"contrasts")$cyl
#> [,1] [,2]
#> 4 1 0
#> 6 0 1
#> 8 -1 -1
Created on 2022-01-07 by the reprex package (v2.0.1)