6

I've been struggling with converting scaled and centered model coefficients from a glmer model back to uncentered and unscaled values.

I analysed a dataset using GLMM in the lme4 (v1.1.7) package. It involves the calculation of maximum detection range of acoustic receivers and effect of environmental variables.

Sample data:

dd <-   structure(list(SUR.ID = c(10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 
10186L, 10186L, 10186L, 10249L, 10249L, 10249L, 10249L, 10249L, 
10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 
10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 
10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 
10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 10249L, 
10249L, 10249L, 10249L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 10250L, 
10250L, 10250L, 10250L), Valid.detections = c(1L, 4L, 0L, 1L, 
6L, 7L, 0L, 1L, 0L, 0L, 6L, 5L, 3L, 5L, 0L, 0L, 1L, 0L, 0L, 0L, 
2L, 3L, 0L, 1L, 5L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 5L, 3L, 1L, 1L, 
0L, 0L, 5L, 8L, 0L, 1L, 0L, 0L, 3L, 7L, 1L, 2L, 7L, 0L, 7L, 6L, 
0L, 3L, 0L, 1L, 0L, 1L, 2L, 5L, 0L, 3L, 0L, 2L, 1L, 5L, 3L, 0L, 
0L, 2L, 0L, 0L, 0L, 0L, 0L, 3L, 4L, 0L, 2L, 2L, 0L, 3L, 0L, 0L, 
9L, 8L, 0L, 2L, 9L, 0L, 7L, 4L, 0L, 5L, 0L, 2L, 0L, 1L, 2L, 4L, 
3L, 2L, 1L, 1L, 3L, 4L, 1L, 2L, 1L, 3L, 0L, 0L, 0L, 6L, 0L, 5L, 
6L, 1L, 3L, 1L, 1L, 0L, 2L, 1L, 6L, 5L, 2L, 1L, 2L, 0L, 1L, 7L, 
5L, 4L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 4L, 2L, 6L, 0L, 0L, 
0L, 1L, 0L, 0L, 3L, 9L, 0L, 7L, 0L, 2L, 7L, 3L, 0L, 5L, 0L, 1L, 
1L, 9L, 2L, 9L, 1L, 0L, 6L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 3L, 13L, 
0L, 4L, 1L, 1L, 1L, 2L, 1L, 6L, 0L, 2L, 0L, 0L, 0L, 1L, 1L, 11L, 
5L, 0L, 6L, 5L), distance = c(200L, 200L, 200L, 200L, 100L, 100L, 
300L, 300L, 400L, 400L, 50L, 50L, 50L, 50L, 300L, 300L, 200L, 
200L, 400L, 400L, 200L, 200L, 100L, 100L, 100L, 100L, 300L, 300L, 
300L, 300L, 400L, 400L, 50L, 50L, 50L, 50L, 400L, 400L, 100L, 
100L, 200L, 200L, 200L, 200L, 100L, 100L, 100L, 100L, 50L, 300L, 
50L, 300L, 300L, 300L, 400L, 400L, 400L, 400L, 50L, 50L, 200L, 
200L, 200L, 100L, 200L, 100L, 100L, 100L, 300L, 300L, 400L, 400L, 
400L, 50L, 400L, 50L, 50L, 300L, 50L, 300L, 200L, 200L, 200L, 
200L, 100L, 100L, 100L, 100L, 50L, 300L, 50L, 300L, 300L, 300L, 
400L, 400L, 400L, 400L, 50L, 50L, 200L, 200L, 200L, 100L, 200L, 
100L, 100L, 100L, 300L, 300L, 400L, 400L, 400L, 50L, 400L, 50L, 
50L, 300L, 50L, 300L, 200L, 200L, 200L, 200L, 100L, 100L, 300L, 
300L, 400L, 400L, 50L, 50L, 50L, 50L, 300L, 300L, 200L, 200L, 
400L, 400L, 200L, 200L, 100L, 100L, 100L, 100L, 300L, 300L, 300L, 
300L, 400L, 400L, 50L, 50L, 50L, 50L, 400L, 400L, 100L, 100L, 
200L, 200L, 200L, 200L, 100L, 100L, 100L, 100L, 50L, 300L, 50L, 
300L, 300L, 300L, 400L, 400L, 400L, 400L, 50L, 50L, 200L, 200L, 
200L, 100L, 200L, 100L, 100L, 100L, 300L, 300L, 400L, 400L, 400L, 
50L, 400L, 50L, 50L, 300L, 50L, 300L), wind.speed = c(8.9939016, 
8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 
8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 
8.9939016, 8.9939016, 8.9939016, 10.8187512, 10.8187512, 8.9939016, 
8.9939016, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 
10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 
10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 
10.8187512, 8.9939016, 8.9939016, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 
8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 
8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 8.9939016, 
10.8187512, 10.8187512, 8.9939016, 8.9939016, 10.8187512, 10.8187512, 
10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 
10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 10.8187512, 
10.8187512, 10.8187512, 10.8187512, 10.8187512, 8.9939016, 8.9939016, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
2.389683519, 2.389683519, 2.389683519, 2.389683519, 2.389683519, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038, 
4.779367038, 4.779367038, 4.779367038, 4.779367038, 4.779367038
), receiver.depth = c(0.65, 0.65, 0.69, 0.69, 0.685, 0.685, 0.645, 
0.645, 0.645, 0.645, 0.67, 0.67, 0.665, 0.665, 0.705, 0.705, 
1.12, 1.12, 0.73, 0.73, 1.155, 1.155, 1.13, 1.13, 1.155, 1.155, 
1.105, 1.105, 1.155, 1.155, 1.095, 1.095, 1.145, 1.145, 1.14, 
1.14, 1.15, 1.15, 0.65, 0.65, 0.41, 0.41, 0.455, 0.455, 0.405, 
0.405, 0.49, 0.49, 0.415, 0.42, 0.415, 0.42, 0.45, 0.45, 0.43, 
0.43, 0.45, 0.45, 0.51, 0.51, 1.01, 1.01, 1.095, 1.045, 1.095, 
1.045, 1.09, 1.09, 1, 1, 0.975, 0.975, 1.08, 1.055, 1.08, 1.055, 
1.085, 1.095, 1.085, 1.095, 0.41, 0.41, 0.455, 0.455, 0.405, 
0.405, 0.49, 0.49, 0.415, 0.42, 0.415, 0.42, 0.45, 0.45, 0.43, 
0.43, 0.45, 0.45, 0.51, 0.51, 1.01, 1.01, 1.095, 1.045, 1.095, 
1.045, 1.09, 1.09, 1, 1, 0.975, 0.975, 1.08, 1.055, 1.08, 1.055, 
1.085, 1.095, 1.085, 1.095, 0.65, 0.65, 0.69, 0.69, 0.685, 0.685, 
0.645, 0.645, 0.645, 0.645, 0.67, 0.67, 0.665, 0.665, 0.705, 
0.705, 1.12, 1.12, 0.73, 0.73, 1.155, 1.155, 1.13, 1.13, 1.155, 
1.155, 1.105, 1.105, 1.155, 1.155, 1.095, 1.095, 1.145, 1.145, 
1.14, 1.14, 1.15, 1.15, 0.65, 0.65, 0.41, 0.41, 0.455, 0.455, 
0.405, 0.405, 0.49, 0.49, 0.415, 0.42, 0.415, 0.42, 0.45, 0.45, 
0.43, 0.43, 0.45, 0.45, 0.51, 0.51, 1.01, 1.01, 1.095, 1.045, 
1.095, 1.045, 1.09, 1.09, 1, 1, 0.975, 0.975, 1.08, 1.055, 1.08, 
1.055, 1.085, 1.095, 1.085, 1.095), water.temperature = c(20.33, 
20.33, 20.9, 20.9, 20.72, 20.72, 20.365, 20.365, 20.505, 20.505, 
20.445, 20.445, 20.62, 20.62, 20.88, 20.88, 22.775, 22.775, 20.92, 
20.92, 22.86, 22.86, 22.755, 22.755, 22.835, 22.835, 22.765, 
22.765, 22.86, 22.86, 22.78, 22.78, 22.835, 22.835, 22.78, 22.78, 
22.835, 22.835, 20.32, 20.32, 27.925, 27.925, 27.62, 27.62, 27.82, 
27.82, 27.58, 27.58, 27.67, 27.98, 27.67, 27.98, 27.63, 27.63, 
27.64, 27.64, 27.96, 27.96, 27.52, 27.52, 26.21, 26.21, 25.725, 
26.14, 25.725, 26.14, 25.605, 25.605, 26.205, 26.205, 26.255, 
26.255, 25.92, 26.07, 25.92, 26.07, 25.525, 25.795, 25.525, 25.795, 
27.925, 27.925, 27.62, 27.62, 27.82, 27.82, 27.58, 27.58, 27.67, 
27.98, 27.67, 27.98, 27.63, 27.63, 27.64, 27.64, 27.96, 27.96, 
27.52, 27.52, 26.21, 26.21, 25.725, 26.14, 25.725, 26.14, 25.605, 
25.605, 26.205, 26.205, 26.255, 26.255, 25.92, 26.07, 25.92, 
26.07, 25.525, 25.795, 25.525, 25.795, 20.33, 20.33, 20.9, 20.9, 
20.72, 20.72, 20.365, 20.365, 20.505, 20.505, 20.445, 20.445, 
20.62, 20.62, 20.88, 20.88, 22.775, 22.775, 20.92, 20.92, 22.86, 
22.86, 22.755, 22.755, 22.835, 22.835, 22.765, 22.765, 22.86, 
22.86, 22.78, 22.78, 22.835, 22.835, 22.78, 22.78, 22.835, 22.835, 
20.32, 20.32, 27.925, 27.925, 27.62, 27.62, 27.82, 27.82, 27.58, 
27.58, 27.67, 27.98, 27.67, 27.98, 27.63, 27.63, 27.64, 27.64, 
27.96, 27.96, 27.52, 27.52, 26.21, 26.21, 25.725, 26.14, 25.725, 
26.14, 25.605, 25.605, 26.205, 26.205, 26.255, 26.255, 25.92, 
26.07, 25.92, 26.07, 25.525, 25.795, 25.525, 25.795), Habitat = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Drug Channel", class = "factor"), 
    Distance = c(-0.078078746, -0.078078746, -0.078078746, -0.078078746, 
    -0.858866211, -0.858866211, 0.702708718, 0.702708718, 1.483496183, 
    1.483496183, -1.249259944, -1.249259944, -1.249259944, -1.249259944, 
    0.702708718, 0.702708718, -0.078078746, -0.078078746, 1.483496183, 
    1.483496183, -0.078078746, -0.078078746, -0.858866211, -0.858866211, 
    -0.858866211, -0.858866211, 0.702708718, 0.702708718, 0.702708718, 
    0.702708718, 1.483496183, 1.483496183, -1.249259944, -1.249259944, 
    -1.249259944, -1.249259944, 1.483496183, 1.483496183, -0.858866211, 
    -0.858866211, -0.078078746, -0.078078746, -0.078078746, -0.078078746, 
    -0.858866211, -0.858866211, -0.858866211, -0.858866211, -1.249259944, 
    0.702708718, -1.249259944, 0.702708718, 0.702708718, 0.702708718, 
    1.483496183, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    -1.249259944, -0.078078746, -0.078078746, -0.078078746, -0.858866211, 
    -0.078078746, -0.858866211, -0.858866211, -0.858866211, 0.702708718, 
    0.702708718, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    1.483496183, -1.249259944, -1.249259944, 0.702708718, -1.249259944, 
    0.702708718, -0.078078746, -0.078078746, -0.078078746, -0.078078746, 
    -0.858866211, -0.858866211, -0.858866211, -0.858866211, -1.249259944, 
    0.702708718, -1.249259944, 0.702708718, 0.702708718, 0.702708718, 
    1.483496183, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    -1.249259944, -0.078078746, -0.078078746, -0.078078746, -0.858866211, 
    -0.078078746, -0.858866211, -0.858866211, -0.858866211, 0.702708718, 
    0.702708718, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    1.483496183, -1.249259944, -1.249259944, 0.702708718, -1.249259944, 
    0.702708718, -0.078078746, -0.078078746, -0.078078746, -0.078078746, 
    -0.858866211, -0.858866211, 0.702708718, 0.702708718, 1.483496183, 
    1.483496183, -1.249259944, -1.249259944, -1.249259944, -1.249259944, 
    0.702708718, 0.702708718, -0.078078746, -0.078078746, 1.483496183, 
    1.483496183, -0.078078746, -0.078078746, -0.858866211, -0.858866211, 
    -0.858866211, -0.858866211, 0.702708718, 0.702708718, 0.702708718, 
    0.702708718, 1.483496183, 1.483496183, -1.249259944, -1.249259944, 
    -1.249259944, -1.249259944, 1.483496183, 1.483496183, -0.858866211, 
    -0.858866211, -0.078078746, -0.078078746, -0.078078746, -0.078078746, 
    -0.858866211, -0.858866211, -0.858866211, -0.858866211, -1.249259944, 
    0.702708718, -1.249259944, 0.702708718, 0.702708718, 0.702708718, 
    1.483496183, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    -1.249259944, -0.078078746, -0.078078746, -0.078078746, -0.858866211, 
    -0.078078746, -0.858866211, -0.858866211, -0.858866211, 0.702708718, 
    0.702708718, 1.483496183, 1.483496183, 1.483496183, -1.249259944, 
    1.483496183, -1.249259944, -1.249259944, 0.702708718, -1.249259944, 
    0.702708718), Receiver.depth = c(-0.744681049, -0.744681049, 
    -0.612233214, -0.612233214, -0.628789194, -0.628789194, -0.761237028, 
    -0.761237028, -0.761237028, -0.761237028, -0.678457132, -0.678457132, 
    -0.695013111, -0.695013111, -0.562565277, -0.562565277, 0.811581001, 
    0.811581001, -0.47978538, -0.47978538, 0.927472856, 0.927472856, 
    0.84469296, 0.84469296, 0.927472856, 0.927472856, 0.761913064, 
    0.761913064, 0.927472856, 0.927472856, 0.728801105, 0.728801105, 
    0.894360898, 0.894360898, 0.877804918, 0.877804918, 0.910916877, 
    0.910916877, -0.744681049, -0.744681049, -1.539368053, -1.539368053, 
    -1.390364239, -1.390364239, -1.555924032, -1.555924032, -1.274472385, 
    -1.274472385, -1.522812073, -1.506256094, -1.522812073, -1.506256094, 
    -1.406920219, -1.406920219, -1.473144136, -1.473144136, -1.406920219, 
    -1.406920219, -1.208248468, -1.208248468, 0.447349458, 0.447349458, 
    0.728801105, 0.563241313, 0.728801105, 0.563241313, 0.712245126, 
    0.712245126, 0.414237499, 0.414237499, 0.331457603, 0.331457603, 
    0.679133167, 0.596353271, 0.679133167, 0.596353271, 0.695689147, 
    0.728801105, 0.695689147, 0.728801105, -1.539368053, -1.539368053, 
    -1.390364239, -1.390364239, -1.555924032, -1.555924032, -1.274472385, 
    -1.274472385, -1.522812073, -1.506256094, -1.522812073, -1.506256094, 
    -1.406920219, -1.406920219, -1.473144136, -1.473144136, -1.406920219, 
    -1.406920219, -1.208248468, -1.208248468, 0.447349458, 0.447349458, 
    0.728801105, 0.563241313, 0.728801105, 0.563241313, 0.712245126, 
    0.712245126, 0.414237499, 0.414237499, 0.331457603, 0.331457603, 
    0.679133167, 0.596353271, 0.679133167, 0.596353271, 0.695689147, 
    0.728801105, 0.695689147, 0.728801105, -0.744681049, -0.744681049, 
    -0.612233214, -0.612233214, -0.628789194, -0.628789194, -0.761237028, 
    -0.761237028, -0.761237028, -0.761237028, -0.678457132, -0.678457132, 
    -0.695013111, -0.695013111, -0.562565277, -0.562565277, 0.811581001, 
    0.811581001, -0.47978538, -0.47978538, 0.927472856, 0.927472856, 
    0.84469296, 0.84469296, 0.927472856, 0.927472856, 0.761913064, 
    0.761913064, 0.927472856, 0.927472856, 0.728801105, 0.728801105, 
    0.894360898, 0.894360898, 0.877804918, 0.877804918, 0.910916877, 
    0.910916877, -0.744681049, -0.744681049, -1.539368053, -1.539368053, 
    -1.390364239, -1.390364239, -1.555924032, -1.555924032, -1.274472385, 
    -1.274472385, -1.522812073, -1.506256094, -1.522812073, -1.506256094, 
    -1.406920219, -1.406920219, -1.473144136, -1.473144136, -1.406920219, 
    -1.406920219, -1.208248468, -1.208248468, 0.447349458, 0.447349458, 
    0.728801105, 0.563241313, 0.728801105, 0.563241313, 0.712245126, 
    0.712245126, 0.414237499, 0.414237499, 0.331457603, 0.331457603, 
    0.679133167, 0.596353271, 0.679133167, 0.596353271, 0.695689147, 
    0.728801105, 0.695689147, 0.728801105), Transmitter.depth = c(-1.126364339, 
    -1.126364339, -0.821720789, -0.821720789, -0.702512443, -0.702512443, 
    -0.066734598, -0.066734598, 0.06571912, 0.06571912, 0.118700607, 
    0.118700607, 0.118700607, 0.118700607, 0.171682094, 0.171682094, 
    0.317381183, 0.317381183, 0.343871927, 0.343871927, 0.343871927, 
    0.343871927, 0.754478451, 0.754478451, 0.780969195, 0.780969195, 
    1.337274809, 1.337274809, 1.416747039, 1.416747039, 1.469728526, 
    1.469728526, 1.509464642, 1.509464642, 1.509464642, 1.509464642, 
    1.602182244, 1.602182244, -0.742248558, -0.742248558, -0.848211532, 
    -0.848211532, -0.689267071, -0.689267071, -0.583304097, -0.583304097, 
    -0.119716085, -0.119716085, 0.211418209, 0.211418209, 0.211418209, 
    0.211418209, 0.264399696, 0.264399696, 0.343871927, 0.343871927, 
    0.37036267, 0.37036267, 0.608779362, 0.608779362, 0.780969195, 
    0.780969195, 1.072367374, 1.072367374, 1.072367374, 1.072367374, 
    1.469728526, 1.469728526, 1.774372077, 1.774372077, 1.800862821, 
    1.800862821, 1.999543397, 1.999543397, 1.999543397, 1.999543397, 
    2.065770256, 2.065770256, 2.065770256, 2.065770256, -0.848211532, 
    -0.848211532, -0.689267071, -0.689267071, -0.583304097, -0.583304097, 
    -0.119716085, -0.119716085, 0.211418209, 0.211418209, 0.211418209, 
    0.211418209, 0.264399696, 0.264399696, 0.343871927, 0.343871927, 
    0.37036267, 0.37036267, 0.608779362, 0.608779362, 0.780969195, 
    0.780969195, 1.072367374, 1.072367374, 1.072367374, 1.072367374, 
    1.469728526, 1.469728526, 1.774372077, 1.774372077, 1.800862821, 
    1.800862821, 1.999543397, 1.999543397, 1.999543397, 1.999543397, 
    2.065770256, 2.065770256, 2.065770256, 2.065770256, -1.126364339, 
    -1.126364339, -0.821720789, -0.821720789, -0.702512443, -0.702512443, 
    -0.066734598, -0.066734598, 0.06571912, 0.06571912, 0.118700607, 
    0.118700607, 0.118700607, 0.118700607, 0.171682094, 0.171682094, 
    0.317381183, 0.317381183, 0.343871927, 0.343871927, 0.343871927, 
    0.343871927, 0.754478451, 0.754478451, 0.780969195, 0.780969195, 
    1.337274809, 1.337274809, 1.416747039, 1.416747039, 1.469728526, 
    1.469728526, 1.509464642, 1.509464642, 1.509464642, 1.509464642, 
    1.602182244, 1.602182244, -0.742248558, -0.742248558, -0.848211532, 
    -0.848211532, -0.689267071, -0.689267071, -0.583304097, -0.583304097, 
    -0.119716085, -0.119716085, 0.211418209, 0.211418209, 0.211418209, 
    0.211418209, 0.264399696, 0.264399696, 0.343871927, 0.343871927, 
    0.37036267, 0.37036267, 0.608779362, 0.608779362, 0.780969195, 
    0.780969195, 1.072367374, 1.072367374, 1.072367374, 1.072367374, 
    1.469728526, 1.469728526, 1.774372077, 1.774372077, 1.800862821, 
    1.800862821, 1.999543397, 1.999543397, 1.999543397, 1.999543397, 
    2.065770256, 2.065770256, 2.065770256, 2.065770256), Water.temperature = c(-1.820795427, 
    -1.820795427, -1.57382909, -1.57382909, -1.65181846, -1.65181846, 
    -1.805630828, -1.805630828, -1.744972429, -1.744972429, -1.770968885, 
    -1.770968885, -1.695145887, -1.695145887, -1.582494576, -1.582494576, 
    -0.761439823, -0.761439823, -1.565163604, -1.565163604, -0.724611509, 
    -0.724611509, -0.770105308, -0.770105308, -0.735443366, -0.735443366, 
    -0.765772566, -0.765772566, -0.724611509, -0.724611509, -0.759273452, 
    -0.759273452, -0.735443366, -0.735443366, -0.759273452, -0.759273452, 
    -0.735443366, -0.735443366, -1.82512817, -1.82512817, 1.469922697, 
    1.469922697, 1.337774043, 1.337774043, 1.424428898, 1.424428898, 
    1.320443072, 1.320443072, 1.359437757, 1.493752783, 1.359437757, 
    1.493752783, 1.342106786, 1.342106786, 1.346439529, 1.346439529, 
    1.485087297, 1.485087297, 1.294446616, 1.294446616, 0.726857314, 
    0.726857314, 0.516719291, 0.696528115, 0.516719291, 0.696528115, 
    0.464726378, 0.464726378, 0.724690943, 0.724690943, 0.746354657, 
    0.746354657, 0.601207774, 0.666198916, 0.601207774, 0.666198916, 
    0.430064436, 0.54704849, 0.430064436, 0.54704849, 1.469922697, 
    1.469922697, 1.337774043, 1.337774043, 1.424428898, 1.424428898, 
    1.320443072, 1.320443072, 1.359437757, 1.493752783, 1.359437757, 
    1.493752783, 1.342106786, 1.342106786, 1.346439529, 1.346439529, 
    1.485087297, 1.485087297, 1.294446616, 1.294446616, 0.726857314, 
    0.726857314, 0.516719291, 0.696528115, 0.516719291, 0.696528115, 
    0.464726378, 0.464726378, 0.724690943, 0.724690943, 0.746354657, 
    0.746354657, 0.601207774, 0.666198916, 0.601207774, 0.666198916, 
    0.430064436, 0.54704849, 0.430064436, 0.54704849, -1.820795427, 
    -1.820795427, -1.57382909, -1.57382909, -1.65181846, -1.65181846, 
    -1.805630828, -1.805630828, -1.744972429, -1.744972429, -1.770968885, 
    -1.770968885, -1.695145887, -1.695145887, -1.582494576, -1.582494576, 
    -0.761439823, -0.761439823, -1.565163604, -1.565163604, -0.724611509, 
    -0.724611509, -0.770105308, -0.770105308, -0.735443366, -0.735443366, 
    -0.765772566, -0.765772566, -0.724611509, -0.724611509, -0.759273452, 
    -0.759273452, -0.735443366, -0.735443366, -0.759273452, -0.759273452, 
    -0.735443366, -0.735443366, -1.82512817, -1.82512817, 1.469922697, 
    1.469922697, 1.337774043, 1.337774043, 1.424428898, 1.424428898, 
    1.320443072, 1.320443072, 1.359437757, 1.493752783, 1.359437757, 
    1.493752783, 1.342106786, 1.342106786, 1.346439529, 1.346439529, 
    1.485087297, 1.485087297, 1.294446616, 1.294446616, 0.726857314, 
    0.726857314, 0.516719291, 0.696528115, 0.516719291, 0.696528115, 
    0.464726378, 0.464726378, 0.724690943, 0.724690943, 0.746354657, 
    0.746354657, 0.601207774, 0.666198916, 0.601207774, 0.666198916, 
    0.430064436, 0.54704849, 0.430064436, 0.54704849), Wind.speed = c(0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.860769967, 0.860769967, 0.342568876, 0.342568876, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.342568876, 0.342568876, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, 0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.342568876, 0.342568876, 0.342568876, 0.342568876, 0.342568876, 
    0.860769967, 0.860769967, 0.342568876, 0.342568876, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.860769967, 0.860769967, 0.860769967, 
    0.860769967, 0.860769967, 0.342568876, 0.342568876, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -1.532825682, 
    -1.532825682, -1.532825682, -1.532825682, -1.532825682, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153, -0.854229153, 
    -0.854229153, -0.854229153, -0.854229153, -0.854229153)), .Names = c("SUR.ID", 
"Valid.detections", "distance", "wind.speed", "receiver.depth", 
"water.temperature", "Habitat", "Distance", "Receiver.depth", 
"Transmitter.depth", "Water.temperature", "Wind.speed"), class = "data.frame", row.names = c(NA, 
-200L))

Prior to data analysis, I needed to scale and center my predictors. I did this using:

scale(... , center=T, scale=T)

The scaled variables in df start with a capital, the unscaled don't.

The model that I obtained looks like this

m1 <- glmer(Valid.detections ~ Transmitter.depth + Receiver.depth + Water.temperature + 
                Wind.speed + Distance + (Distance | SUR.ID), data=df, family = poisson)

Now that I have all the coefficients of the predictors, I wish to calculate the distance at which the number of detections = y = 0, given certain environmental values (calculation not shown here).

x <- seq(from=1, to=1000)
X <- as.data.frame(x)     
 y <- exp(fixef(m2gg)["(Intercept)"] + fixef(m2gg)["Distance"]*X + fixef(m2gg)["Transmitter.depth"]*0.6067926 + 
      fixef(m2gg)["Receiver.depth"]*-0.1610828 + fixef(m2gg)["Water.temperature"]*-0.1128282 + 
      fixef(m2gg)["Wind.speed"]*-0.2959290)

However, since I scaled and centered all predictors, there's a need to "unscale" and "uncenter" the value of distance to make sense out of the calculated value for distance.

UPDATE:: While the parameter values above are fixed numbers, actually they are the values of only one receiver. Ultimately, I would like to calculate the maximum range of multiple receivers given random intercepts and random slopes for distance for each receiver, taken from the mini sample data below

sample2 <- structure(list(X.Intercept. = c(-0.101691254, -0.184443307), 
        distance = c(0.002089427, -0.00065884), SUR.ID = 10185:10186, 
        water.temperature = c(24.272, 24.272), transmitter.depth = c(1.54925, 
        1.54925), receiver.depth = c(0.82625, 0.82625), wind.speed = c(6.745425839, 
        6.745425839), Water.temperature = c(-0.112828232, -0.112828232
        ), Transmitter.depth = c(0.606792556, 0.606792556), Receiver.depth = c(-0.16108278, 
        -0.16108278), Wind.speed = c(-0.295928998, -0.295928998)), .Names = c("X.Intercept.", 
    "distance", "SUR.ID", "water.temperature", "transmitter.depth", 
    "receiver.depth", "wind.speed", "Water.temperature", "Transmitter.depth", 
    "Receiver.depth", "Wind.speed"), class = "data.frame", row.names = c(NA, 
    -2L))

I don't seem to be able to wrap your last 3 commands in a loop function that runs through the 3 commands as many times as there are receivers

L <- length(sample2$SUR.ID)
for (i in 1:L){
vals[i] <- '(Intercept)'=sample2[i,1],Transmitter.depth=sample2[i,11],
              Receiver.depth=sample2[i,8],Water.temperature=sample2[i,10],
              Wind.speed=sample2[i,13],distance=dist)
pred.obs[i] <- exp(cc %*% t(vals[i]))
max(dist[pred.obs>1])[i]
}
FlyingDutch
  • 781
  • 2
  • 11
  • 20
  • does http://stackoverflow.com/questions/23642111/how-to-unscale-the-coefficients-from-an-lmer-model-fitted-with-a-scaled-respon/23643740#23643740 answer your question? – Ben Bolker Jun 17 '14 at 17:24
  • @Ben: I should've included this information in my OP. I'm aware of this thread, since it's the only one that discusses unscaling. However, I do not understand your solution. By copy pasting your proposed solution to see how scaling and rescaling (unscaling?) works, I tried to understand it step by step. However, it doesn't seem to undo the scaling, as it doesn't produce the starting values of the predictors. – FlyingDutch Jun 17 '14 at 19:10
  • Can you give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? Same data as http://stackoverflow.com/questions/23478792/warning-messages-when-trying-to-run-glmer-in-r ? – Ben Bolker Jun 17 '14 at 20:30
  • @Ben: I updated my OP, and provided a reproducible example. It's similar to the data in my other post, but slightly more lean, and have scaled and centered predictors included. Thanks. – FlyingDutch Jun 18 '14 at 07:47

1 Answers1

6

Read in data:

source("SO_unscale.txt")

Separate unscaled and scaled variables (Transmitter.depth doesn't appear to have a scaled variant)

unsc.vars <- subset(dd,select=c(Transmitter.depth,
                       receiver.depth,water.temperature,
                       wind.speed,distance))
sc.vars <- subset(dd,select=c(Transmitter.depth,
                     Receiver.depth,Water.temperature,
                     Wind.speed,Distance))

I noticed that the means and standard deviations of the scaled variables were not exactly 0/1, perhaps because what's here is a subset of the data. In any case, we will need the means and standard deviations of the original data in order to unscale.

colMeans(sc.vars)
apply(sc.vars,2,sd)
cm <- colMeans(unsc.vars)
csd <- apply(unsc.vars,2,sd)

It is possible to 'unscale' even if the new variables are not exactly centered/scaled (one would just need to enter the actual amount of the shift/scaling done), but it's marginally more complicated, so I'm just going to go ahead and fit with precisely centered/scaled variables.

## changed data name to dd
library(lme4)
cs. <- function(x) scale(x,center=TRUE,scale=TRUE)
m1 <- glmer(Valid.detections ~ Transmitter.depth +
            receiver.depth + water.temperature + 
            wind.speed + distance + (distance | SUR.ID),
            data=dd, family = poisson,
            control=glmerControl(optimizer=c("bobyqa","Nelder_Mead")))
## FAILS with bobyqa alone
m1.sc <- glmer(Valid.detections ~ cs.(Transmitter.depth) +
               cs.(receiver.depth) + cs.(water.temperature) + 
               cs.(wind.speed) + cs.(distance) + (cs.(distance) | SUR.ID),
               data=dd, family = poisson,
               control=glmerControl(optimizer=c("bobyqa","Nelder_Mead")))

An important point is that in this case the very different scaling doesn't seem to do any harm; the scaled and unscaled model get essentially the same goodness of fit (if it were important, we would expect the scaled fit to do better)

logLik(m1)-logLik(m1.sc)  ## 1e-7

Here is the rescaling function given in a previous answer:

rescale.coefs <- function(beta,mu,sigma) {
    beta2 <- beta ## inherit names etc.
    beta2[-1] <- sigma[1]*beta[-1]/sigma[-1]
    beta2[1]  <- sigma[1]*beta[1]+mu[1]-sum(beta2[-1]*mu[-1])
    beta2
}     

The parameters do indeed match very closely. (The shifting/scaling vectors include possible scaling/shifting of the response variable, so we start with 0/1 since the response is not scaled [it would rarely make sense to scale a response variable for a GLMM, but this function can be useful for LMMs too].)

(cc <- rescale.coefs(fixef(m1.sc),mu=c(0,cm),sigma=c(1,csd)))
##            (Intercept) cs.(Transmitter.depth)    cs.(receiver.depth) 
##            3.865879406            0.011158402           -0.554392645 
## cs.(water.temperature)        cs.(wind.speed)          cs.(distance) 
##           -0.050833325           -0.042188495           -0.007231021 

fixef(m1)
##  (Intercept) Transmitter.depth    receiver.depth water.temperature 
##  3.865816422       0.011180213      -0.554498582      -0.050830611 
##   wind.speed          distance 
## -0.042179333      -0.007231004 

Since they're the same (since the unscaled model does fit OK), we could use either set for this calculation.

ddist <- 1:1000
vals <- cbind(`(Intercept)`=1,Transmitter.depth=0.6067926,
          Receiver.depth=-0.1610828,Water.temperature=-0.1128282,
          Wind.speed=-0.2959290,distance=ddist)
pred.obs <- exp(cc %*% t(vals))
max(ddist[pred.obs>1])

Now suppose you want to do similar scaling/unscaling for a model with interactions or other complexities (i.e. the predictor variables, the columns of the fixed-effect model matrix, are not the same as the input variables, which are the variables that appear in the formula)

m2 <- update(m1,. ~ . + wind.speed:distance)
m2.sc <- update(m1.sc,. ~ . + I(cs.(wind.speed*distance)))
logLik(m2)-logLik(m2.sc)

Calculate mean/sd of model matrix, dropping the first (intercept) value:

X <- getME(m2,"X")                                        
cm2 <- colMeans(X)[-1]
csd2 <- apply(X,2,sd)[-1]                                            
(cc2 <- rescale.coefs(fixef(m2.sc),mu=c(0,cm2),sigma=c(1,csd2)))
all.equal(unname(cc2),unname(fixef(m2)),tol=1e-3)  ## TRUE

You don't actually have to fit the full unscaled model just to get the scaling parameters: you could use model.matrix([formula],data) to derive the model matrix. That is, if you haven't already fitted m2 and you want to get X to get the column means and standard deviations, i.e.

X <- model.matrix(Valid.detections ~ Transmitter.depth + receiver.depth +
                      water.temperature + 
                      wind.speed + distance + 
                      wind.speed:distance,
                  data=dd)

If you have a LMM/have scaled the response variable, you should also multiply all of the standard deviations (including the residual error, sigma(fitted_model)) by the original SD of the response variable.

Ben Bolker
  • 173,430
  • 21
  • 312
  • 389
  • Thank you, this is awesome! Once again you save the day. Exactly what I wanted. You are right, the unscaled transmitter depth is missing, but I get the point. – FlyingDutch Jun 18 '14 at 14:11
  • I reran your script on my full dataset, fitting the unscaled and scaled model. I ran "(cc – FlyingDutch Jun 18 '14 at 15:09
  • hmm. have you compared `length(fixef(m1.sc))`, `length(cm)`, `length(csd)`? I believe the latter should be one shorter than the former (the fixed effects include an intercept term; by design the `mu` and `sigma` arguments are the same length as `beta`, they contain one term for the scaling of the response plus terms for the scaling of each fixed-effect parameter). Perhaps you have a categorical variable or some other kind of 'derived' predictor variable in your model? – Ben Bolker Jun 18 '14 at 17:07
  • Yes, i have 3 categorical predictors and 6 interactions between categorical predictors and variables: length(fixef) = 15, length(cm) = 5, length(csd) = 5. And how do I take into account random intercept and slope? (please see the update in my OP) – FlyingDutch Jun 19 '14 at 11:17
  • (1) you have to unscale based on the columns of the *model matrix* (i.e. technically speaking the predictor variables rather than the input variables; (2) taking account of the random effects is a bit of a can of worms, it might warrant another question (`r-sig-mixed-models` might be more appropriate), (3) *if* your scaled and unscaled models converge to the same likelihood then you can ignore the warning and don't have to fuss with all of this scaling stuff anyway. – Ben Bolker Jun 19 '14 at 12:08
  • Hi Ben, the difference in log likelihood between unscaled and scaled model is -0.08... Is this acceptable? Can I work with the unscaled model to calculate maximum detection ranges? – FlyingDutch Sep 08 '14 at 15:58
  • I'm afraid that "acceptable" is sort of up to you. In this case I think the question would be how much difference there is in the predictions of the model for a particular case, and whether that is large enough that you would be concerned. – Ben Bolker Sep 08 '14 at 16:20
  • @Ben Bolker. Very helpful function. Thanks. Can this also be used for unscaling the SE from the model fit? Also, in my case, I am unable to fit the unsclaed model without warning messages. It seems like I can still use your function, but I am wondering what you mean in your last tow lines `You don't actually have to fit the full unscaled model just to get the scaling parameters: you could use model.matrix([formula],data) to derive the model matrix.` I can make a new post as well. – B. Davis Feb 15 '16 at 19:06