gpt4 book ai didi

r - unscale 和 uncenter glmer 参数

转载 作者:行者123 更新时间:2023-12-04 12:16:40 27 4
gpt4 key购买 nike

我一直在努力将缩放和居中的模型系数从 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 中的缩放变量以大写开头,未缩放的变量不以大写开头。

我获得的模型看起来像这样
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)

但是,由于我对所有预测变量进行了缩放和居中,因此需要“取消缩放”和“取消中心化”距离值以从计算出的距离值中理解。

更新: : 上面的参数值虽然是固定数字,但实际上只是一个接收器的值。最终,我想计算多个接收器的最大范围,给定随机截距和每个接收器距离的随机斜率,取自下面的小样本数据
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]
}

最佳答案

读入数据:

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

由于它们是相同的(因为未缩放的模型确实适合),我们可以使用任一集合进行此计算。
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)

计算模型矩阵的均值/标准差,去掉第一个(截距)值:
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。

关于r - unscale 和 uncenter glmer 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24268031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com