4
$\begingroup$

I am developing a mixed-effects binomial logistic regression (using glmmTMB, family = binomial) where the response is presence-absence. One of my potential predictors is hour of day, which takes values from 0 to 23.

z$newHour <- 2 * pi * (z$Hour / 24)
m1.glmm <- glmmTMB(pa~ (1 | FishID) + Year + sin(newHour) + 
    cos(newHour) + Sex + tempC + I(tempC**2), 
    family = binomial, data = z, na.action = na.fail)

One of the answers to the post here:

Regression using circular variable (hour from 0~23) as predictor suggests mapping the circular predictor to the interval to (0, 2pi) and including two terms in the model—one for the sine of the transformed predictor and one for the cosine of the transformed predictor.

I have followed that advice and run the model. In performing significance testing for covariates, only the sine of the transformed predictor (not the cosine of the transformed predictor) comes out as significant. Is this possible and does it make sense?

I also have a question regarding the construction of the associated predictor effect plot. Currently, the x-axis of the plot is on the transformed scale. Is it possible to convert it in some way so the x-axis is on the 0 to 23 scale?

predictor effect plot for hour of day

$\endgroup$
2
  • 1
    $\begingroup$ Can you post some of your code and output so we can see what you're seeing? $\endgroup$ Commented Aug 1 at 16:12
  • $\begingroup$ I added code an the image I am referring to. Please let me know if more info is needed. Thank you! $\endgroup$
    – Laura
    Commented Aug 1 at 16:24

1 Answer 1

8
$\begingroup$

Even with a simple sinusoidal wave, you need both the sine and cosine terms to fit the phase of the wave. Wikipedia shows that the sum of sine and cosine terms in your model can be written in terms of the phase shift $\varphi$ of a scaled cosine function:

$$a\cos x+b\sin x=c\cos(x+\varphi)$$ where $c$ and $\varphi$ are defined as so:

\begin{align} c &= \text{sgn} (a) \sqrt{a^2 + b^2}, \\ \varphi &= {\arctan}\bigl({-b/a}\bigr), \end{align}

given that $a \neq 0.$

Using the single cosine term with a phase shift in a regression model would lead to a model non-linear in the $\varphi$ coefficient. Using a sum of cosine and sine terms allows standard linear regression (which is linear in the coefficients). Even if the coefficient of your cosine term is "statistically insignificant" it certainly should be kept in the model. Your finding just means that your data come close to matching a sine function without a phase shift ($a\approx0$ in the first equation above).

One simple way to get the x-axis scale that you want is to not define a newHour variable like you did. Just use the forms shown on the page you cite, with Hour as the predictor variable and the constant $2\pi/24=\pi/12$ kept within the trigonometric functions:

m1.glmm <- glmmTMB(pa~ (1 | FishID) + Year + sin(pi*Hour/12) + cos(pi*Hour/12) + Sex + tempC + I(tempC**2), 
                family = binomial,
                data = z,
                na.action = na.fail)

I suppose you could continue to use the newHour scale and manipulate the x-axis scale values to do the inverse of the newHour transformation, but that's more work.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.