# Likelihood ratio test in R for categorical variables

I am working with behavioral data of male sea lions, with a binomial model to understand the effect of different variables in determining the location where the encounters between males occur (Land -vs- water). For this I have several quantitative and categorical variables.

I am testing the significance of the odds ratio for each variable using likelihood ratio tests.

For my dataset the variable "Temperature" was divided into 3 different categories: "1" values<20ºC, "2" values between 20ºC and 30ºC, and "3" values>30ºC.

The results of the odds ratio shows that the odds of an aggressive interaction occurring on the land increase in 9% when going from the first temperature interval (<20ºC) to the second interval (20ºC-30º). However, the odds of an aggressive interaction occurring on land decrease in 8% when going from the second temperature interval (20ºC-30º) to the third interval (>30ºC).

When applying the likelihood ratio test (lrtest function) to these data it gives me a single value of P, but what I need is one value for each change of the variable: one for the change between the first and the second interval, and one for the change between the second and the third interval.

It means I need the likelihood ratio test to include the categorical variable, to understand the significance of each odds ratio.

The script I used is this one:

# MODEL WITH ALL VARIABLES

> J_mod.a <- glm(as.factor(Place) ~ as.factor(TempF) + as.factor (AgType) + FemDen,  data=JUNE, family=binomial("logit"))
> J_mod.a

Call:  glm(formula = as.factor(Place) ~ as.factor(TempF) + as.factor(AgType) +
FemDen, family = binomial("logit"), data = JUNE)

Coefficients:
(Intercept)   as.factor(TempF)2   as.factor(TempF)3  as.factor(AgType)2
1.34820             0.08229            -2.53280            -1.73712
FemDen
0.11443

Degrees of Freedom: 124 Total (i.e. Null);  120 Residual
(7 observations deleted due to missingness)
Null Deviance:      159.6

# MODEL WITHOUT TEMPERATURE

> J_mod.TEMP <- glm(as.factor(Place) ~ as.factor (AgType) + FemDen, data=JUNE,   family=binomial("logit"))
> J_mod.TEMP

Call:  glm(formula = as.factor(Place) ~ as.factor(AgType) + FemDen,
family = binomial("logit"), data = JUNE)

Coefficients:
(Intercept)  as.factor(AgType)2              FemDen
0.01463            -1.77035             0.08361

Degrees of Freedom: 124 Total (i.e. Null);  122 Residual
(7 observations deleted due to missingness)
Null Deviance:      159.6
Residual Deviance: 129.4    AIC: 135.4

# LIKELIHOOD RATIO TEST BETWEEN THE 2 MODELS

> J_LRT_TEMP <- lrtest (J_mod.a, J_mod.TEMP)
> J_LRT_TEMP

Model 1: as.factor(Place) ~ as.factor(TempF) + as.factor(AgType) + FemDen
Model 2: as.factor(Place) ~ as.factor(AgType) + FemDen

L.R. Chisq         d.f.            P
2.371378e+01 2.000000e+00 7.089530e-06


I thank you in advance for all of you who can take some of your time to let me know what am I doing wrong, or what am I missing here.

Best.

If you are interested in comparing the different levels of the variable temperature, summary(J_mod.TEMP) will give you the p-values. Note that Ruses dummy coding by default, so the first coefficient contrasts level 2 vs. 1 and the second coefficient level 3 vs. 1. You may use contrasts to adapt this to your personl needs.