3

I have fitted a lmer model, and now I am trying to interpret the coefficients in terms of the real coefficients instead of scaled ones.

My top model is:

 lmer(logcptplus1~scale.t6+scale.logdepth+(1|location) + (1|Fyear),data=cpt, REML=TRUE)

so both the predictor variables are scaled, with one being the scaled log values. my response variable is not scaled and just logged.

to scale my predictor variables, I used the scale(data$column, center=TRUE,scale=TRUE) function in r.

The output for my model is: Fixed effects:

                Estimate Std. Error t value
  (int)         3.31363    0.15163  21.853
scale.t6       -0.34400    0.10540  -3.264
scale.logdepth -0.58199    0.06486  -8.973

so how can I obtain real estimates for my response variable from these coefficients that are scaled based on my scaled predictor variables?

NOTE: I understand how to unscale my predictor variables, just not how to unscale/transform the coefficients

Thanks

user4093066
  • 33
  • 1
  • 4

1 Answers1

4

The scale function does a z-transform of the data, which means it takes the original values, subtracts the mean, and then divides by the standard deviation.

to_scale <- 1:10
using_scale <- scale(to_scale, center = TRUE, scale = TRUE)
by_hand <- (to_scale - mean(to_scale))/sd(to_scale)
identical(as.numeric(using_scale), by_hand)
[1] TRUE

Therefore, to reverse the model coefficients all you need to do is multiply the coefficient by the standard deviation of the covariate and add the mean. The scale function holds onto the mean and sd for you. So, if we assume that your covariate values are the using_scale vector for the scale.t6 regression coefficient we can write a function to do the work for us.

get_real <- function(coef, scaled_covariate){

            # collect mean and standard deviation from scaled covariate
            mean_sd <- unlist(attributes(scaled_covariate)[-1])

            # reverse the z-transformation
             answer <- (coef * mean_sd[2]) + mean_sd[1]

            # this value will have a name, remove it
             names(answer) <- NULL

            # return unscaled coef
              return(answer)
}

get_real(-0.3440, using_scale)
[1] 4.458488

In other words, it is the same thing as unscaling your predictor variables because it is a monotonic transformation.

mfidino
  • 3,030
  • 1
  • 9
  • 13
  • Thank you, but how does this translate for the intercept as well? The intercept is scaled to both of the variables too, right? Do you know how to transform that? I'm new to lmers and mixed models in general and I am struggling with getting real parameter estimates from my model as a whole – user4093066 Feb 05 '16 at 17:13
  • Correct, the intercept is dependent on both variables in the model, and there would not be a way to transform it. If want to get real parameter estimates I would suggest not scaling your parameters from the get go. The primary reason for scaling (aside from potentially helping computationally) is so you can make comparisons between parameter estimates. The real question is why you would actually need real parameter estimates anyways. Just plot out predictions for each parameter and replace the x axis with the real values. – mfidino Feb 05 '16 at 17:23
  • I would think the OP wants real parameter estimates for inference sake... – theforestecologist May 07 '18 at 18:24
  • You can back-transform the intercept to: see https://stackoverflow.com/questions/24268031/unscale-and-uncenter-glmer-parameters/24286763#24286763 – Ben Bolker May 02 '23 at 23:44