0

I have made a simple gls model with a continuous variable as the response and a categorical as the predictor. I have used box Cox transformation to the response because it was highly skewed. How can I back transform the coefficients and their CI? I used nlme for gls. A sample dataset:

structure(list(station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L
), levels = c("5027", "5047", "5061", "5117", "5155", "5177", 
"5180", "5192", "5211", "5235", "5243", "5251", "5279", "5340", 
"5359", "5370", "5390", "5415", "5422", "5445", "5465", "5479", 
"5490", "5515", "5540", "5590", "5710", "5750", "5845", "5925", 
"5955", "5980", "5990", "6019", "6031", "6041", "6052", "6058", 
"6065", "6072", "6074", "6082", "6102", "6109", "6116", "6119", 
"6126", "6135", "6136", "6141", "6156", "6159", "6174", "6188", 
"6193", "6197"), class = "factor"), temp = c(10.5, 17.6, 11, 
24, 12.8, 19.37, 16.4, 12.13, 15.5, 22.4, 10.3, 10.6, 12.6, 11.6, 
16.2, 11.43, 16.1, 11.35, 11.73, 16.95, 12.4, 11, 16.15, 14.5, 
16.1, 16.15, 11.3, 17.8, 11.9, 12.03, 11.4, 13.12, 17.6, 12.6, 
13.38, 15.5, 10.6, 15.1, 16.9, 12.6, 14, 13.2, 20.35, 24.4, 13.3, 
17.3, 10.65, 12.2, 13.6, 15.9, 14.4, 11.4, 13.3, 12.95, 25.1, 
10.1, 20.2, 11, 10.6, 11.7, 12.57, 11.2, 11, 16.2, 17.5, 12.63, 
10.9, 10.6, 17.95, 18.9), long = c(10.5258406305778, 10.5258406305778, 
10.5258406305778, 10.5258406305778, 10.5258406305778, 10.5258406305778, 
10.5258406305778, 10.5258406305778, 10.5258406305778, 10.5258406305778, 
10.5258406305778, 10.5258406305778, 10.5258406305778, 10.5258406305778, 
10.5258406305778, 10.5258406305778, 10.5258406305778, 10.5258406305778, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.86228239692001, 9.86228239692001, 9.86228239692001, 9.86228239692001, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299, 
9.55890424235299, 9.55890424235299, 9.55890424235299, 9.55890424235299
), lat = c(57.4260382548796, 57.4260382548796, 57.4260382548796, 
57.4260382548796, 57.4260382548796, 57.4260382548796, 57.4260382548796, 
57.4260382548796, 57.4260382548796, 57.4260382548796, 57.4260382548796, 
57.4260382548796, 57.4260382548796, 57.4260382548796, 57.4260382548796, 
57.4260382548796, 57.4260382548796, 57.4260382548796, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.9732372789987, 
56.9732372789987, 56.9732372789987, 56.9732372789987, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265, 56.1603237202265, 
56.1603237202265, 56.1603237202265, 56.1603237202265), year = c(1990, 
1991, 1992, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 
2011, 2012, 2014, 2017, 2018, 2019, 1979, 1981, 1983, 1984, 1987, 
1988, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 
2009, 2010, 2011, 2012, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 
2022, 1980, 1982, 1983, 1984, 1988, 1997, 1998, 1999, 2000, 2001, 
2002, 2004, 2005, 2009, 2010, 2011, 2012, 2014, 2016, 2017, 2018, 
2020, 2021, 2022), test.bc = c(0.559839770954862, 0.565284201434495, 
0.560556225709956, 0.566831194324542, 0.562522629786345, 0.565854817249371, 
0.56479772703557, 0.561884127815748, 0.564363080689475, 0.566556040366, 
0.559526043258447, 0.559990542945858, 0.562341806600785, 0.561305665047214, 
0.564706869893158, 0.561104304644858, 0.564660270536769, 0.561006658516524, 
0.561454241893781, 0.565032488906873, 0.562152891994338, 0.560556225709956, 
0.564683669673913, 0.563790715686587, 0.564660270536769, 0.564683669673913, 
0.560944659693946, 0.565356590523383, 0.5616418149681, 0.561780343601122, 
0.561067908733378, 0.562796264833387, 0.565284201434495, 0.562341806600785, 
0.563005411163521, 0.564363080689475, 0.559990542945858, 0.564146653514575, 
0.565012014527668, 0.562341806600785, 0.56346150874382, 0.562861828617158, 
0.566113285190366, 0.566892307593349, 0.56294225811913, 0.565171265617297, 
0.560064468460388, 0.561955384464059, 0.563173825474645, 0.564564637659987, 
0.563727389181159, 0.561067908733378, 0.56294225811913, 0.562653218195187, 
0.56699285221528, 0.55919505643473, 0.566075955195481, 0.560556225709956, 
0.559990542945858, 0.561420358676073, 0.562313997064695, 0.560818365873288, 
0.560556225709956, 0.564706869893158, 0.565247148921889, 0.562369434146698, 
0.56042015881917, 0.559990542945858, 0.565409427883572, 0.565717580038285
)), row.names = c(NA, -70L), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"), groups = structure(list(station = structure(c(1L, 
3L, 8L), levels = c("5027", "5047", "5061", "5117", "5155", "5177", 
"5180", "5192", "5211", "5235", "5243", "5251", "5279", "5340", 
"5359", "5370", "5390", "5415", "5422", "5445", "5465", "5479", 
"5490", "5515", "5540", "5590", "5710", "5750", "5845", "5925", 
"5955", "5980", "5990", "6019", "6031", "6041", "6052", "6058", 
"6065", "6072", "6074", "6082", "6102", "6109", "6116", "6119", 
"6126", "6135", "6136", "6141", "6156", "6159", "6174", "6188", 
"6193", "6197"), class = "factor"), .rows = structure(list(1:18, 
    19:46, 47:70), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), row.names = c(NA, -3L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE))

and the code:

#Box-cox tranformation
#Simple linear regression
lo <- lm(temp ~ station, data=test2)

BCTransform <- function(y, lambda=0) {
  if (lambda == 0L) { log(y) }
  else { (y^lambda - 1) / lambda }
}
bc <-boxcox(lo)
bc.power <- bc$x[which.max(bc$y)]
test2$test.bc <- BCTransform(test2$temp, bc.power)
#gls
model4 <- gls(test.bc ~ station,
              correlation= corExp(1, form = ~ long + lat| year), data=test2)

How can I: (A)Back transform the coefficients and their CI (B)Back transform the emmeans

les2004
  • 105
  • 7
  • With no data and no code this is more suited for stats.stackexchange.com. On SO it will probably be considered “not a coding problem”. – IRTFM May 24 '23 at 16:12
  • `emmeans::make.tran()` already includes "boxcox" as an option. It looks like `emmeans` handles `gls` models. So if you provide a [mcve], someone can show you how to do this (the section on "special transformations" in `vignette("transformations", "emmeans")` does show a very similar example ...) – Ben Bolker May 24 '23 at 16:21
  • I have provided a reproducible example. – les2004 May 24 '23 at 16:38
  • I will add that it makes no sense to try to back-transform the model coefficients. You can estimate means and back-transform those, and you can estimate contrasts of those results. See the ["transformations" vignette](https://cran.r-project.org/web/packages/emmeans/vignettes/transformations.html) in **emmeans** – Russ Lenth May 31 '23 at 20:59

0 Answers0