How to remove ordering of the levels from factor variable in R?
If you created your variable via ordered
, it's as simple as resetting its class to factor
.
f <- ordered(letters)class(f) <- "factor"identical(f, factor(letters))
In a linear or additive model (including linear regression, logistic regression and anything fit with lm
, glm
and gam
) a factor predictor is treated exactly the same as an ordered predictor in terms of the overall model fit. You'll get the same predicted values, residuals, lack-of-fit statistics, etc regardless of which one you use.
However, the contrasts are different for the two classes. A factor uses treatment contrasts, ie the usual dummy-variable coding with a given level treated as the baseline. An ordered factor uses polynomial contrasts, which are based on orthogonal polynomials (whatever that means; I've never had a reason to use ordered factors). Because of this, the t-stats and P-values for individual coefficients will be different.