我一直在努力将缩放和居中的模型系数从glmer模型转换回未经中断和未缩放的值。
我在lme4(v1.1.7)包中使用GLMM分析了一个数据集。它涉及声学接收器最大检测范围的计算和环境变量的影响。
示例数据:
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))
在数据分析之前,我需要扩展和预测我的预测因子。我是这样做的:
scale(... , center=T, scale=T)
df中的缩放变量以大写字母开头,未缩放的don t t。
我获得的模型看起来像这样
m1 <- glmer(Valid.detections ~ Transmitter.depth + Receiver.depth + Water.temperature +
Wind.speed + Distance + (Distance | SUR.ID), data=df, family = poisson)
现在我已经拥有了预测变量的所有系数,我希望在给定某些环境值的情况下计算检测次数= y = 0的距离(此处未显示计算)。
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)
然而,由于我缩放并集中了所有预测因子,因此需要&#34; unscale&#34;和&#34; uncenter&#34;距离的计算值中的距离值。
UPDATE::虽然上面的参数值是固定数字,但实际上它们只是一个接收器的值。最后,我想根据随机截距和每个接收器的距离随机斜率计算多个接收器的最大范围,取自下面的迷你样本数据
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))
我似乎无法将最后3个命令包装在循环函数中,该循环函数在3个命令中运行的次数与接收器一样多
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]
}
答案 0 :(得分:6)
读入数据:
source("SO_unscale.txt")
单独的未缩放和缩放变量(Transmitter.depth
似乎没有缩放变体)
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))
我注意到缩放变量的均值和标准偏差不正好是0/1,也许是因为这里的数据是一个子集。在任何情况下,我们都需要原始数据的均值和标准偏差才能进行无标尺。
colMeans(sc.vars)
apply(sc.vars,2,sd)
cm <- colMeans(unsc.vars)
csd <- apply(unsc.vars,2,sd)
即使新变量没有精确居中/缩放(只需要输入实际的移位/缩放量),也可以'取消缩放',但它稍微复杂一点,所以我只是继续前进并适应精确居中/缩放的变量。
## 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")))
重要的一点是,在这种情况下,非常不同的缩放似乎没有任何伤害;缩放和非缩放模型基本上具有相同的拟合优度(如果重要的话,我们希望缩放的拟合做得更好)
logLik(m1)-logLik(m1.sc) ## 1e-7
以下是前一个答案中给出的重新缩放功能:
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
}
参数确实非常接近。 (移位/缩放向量包括响应变量的可能缩放/移位,因此我们从0/1开始,因为响应未缩放[缩放GLMM的响应变量很少有意义,但这个功能对LMM也很有用。)。
(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
由于它们是相同的(因为未缩放的模型 适合OK),我们可以使用任一组进行此计算。
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])
现在假设你想对具有交互或其他复杂性的模型进行类似的缩放/取消缩放(即预测变量,固定效应模型矩阵的列,与输入变量,它们是公式中出现的变量
m2 <- update(m1,. ~ . + wind.speed:distance)
m2.sc <- update(m1.sc,. ~ . + I(cs.(wind.speed*distance)))
logLik(m2)-logLik(m2.sc)
计算模型矩阵的均值/ sd,丢弃第一个(截距)值:
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
为了获得缩放参数,您实际上不需要拟合完整的非缩放模型:您可以使用model.matrix([formula],data)
来导出模型矩阵。也就是说,如果您尚未安装m2
,并且希望X
获得列均值和标准偏差,即
X <- model.matrix(Valid.detections ~ Transmitter.depth + receiver.depth +
water.temperature +
wind.speed + distance +
wind.speed:distance,
data=dd)
如果您有LMM /已缩放响应变量,您还应将所有标准偏差(包括残差,sigma(fitted_model)
)乘以响应变量的原始SD。