# [R] offset in nlme

PIKAL Petr petr.pikal at precheza.cz
Wed Dec 28 11:02:50 CET 2016

```Hi

> -----Original Message-----
> From: Jeff Newmiller [mailto:jdnewmil at dcn.davis.ca.us]
> Sent: Wednesday, December 28, 2016 10:13 AM
> To: PIKAL Petr <petr.pikal at precheza.cz>; r-help mailing list <r-help at r-
> project.org>
> Subject: RE: [R] offset in nlme
>
> You don't need to post WORKING code... just code that leads to the problem
> you want help with. The ability to create the error and then eliminate the
> error greatly reduces guessing on both sides of the conversation about the
> nature of the question. (Things the asker did not know were important
> become clear to the answerer and can be highlighted.)
>
> I think you can also forgo the little function definition if you simply remove R0
> from the start list in your original call to nlme and put a zero in the function
> call.

Yes, you are correct. I am not sure if it is intended but I did not find any mention about this feature in help pages nor in Pinheiro, Bates book.

fit<-nlsList(rutrtg ~ SSasymp(doba, Asym, R0=5, lrc), data=rutil.g, start=c(Asym=100, lrc=-3))
fit1<-nlme(fit, random=Asym+lrc~1)
fixef(fit1)
Asym      lrc
73.77617 -3.31942

Cheers
Petr

For completeness, here are the data.
dput(rutil.g)
structure(list(vzorek = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 5L, 7L, 9L, 11L, 13L,
6L, 8L, 10L, 12L, 14L), .Label = c("01.I", "02.I", "1", "2",
"2/1*A/900C", "2/1*A/950C", "2/1*B/900C", "2/1*B/950C", "2/1*C/900C",
"2/1*C/950C", "2/1*D/900C", "2/1*D/950C", "2/1*E/900C", "2/1*E/950C",
"3", "4"), class = "factor"), promot = c(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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), teplota = c(875L, 875L, 875L, 875L, 875L, 925L, 925L, 925L,
925L, 925L, 875L, 875L, 875L, 875L, 875L, 925L, 925L, 925L, 925L,
925L, 875L, 875L, 875L, 875L, 875L, 925L, 925L, 925L, 925L, 925L,
875L, 875L, 875L, 875L, 875L, 925L, 925L, 925L, 925L, 925L, 875L,
875L, 875L, 875L, 875L, 925L, 925L, 925L, 925L, 925L, 875L, 875L,
875L, 875L, 875L, 925L, 925L, 925L, 925L, 925L, 875L, 875L, 875L,
875L, 875L, 925L, 925L, 925L, 925L, 925L), k2oteor = c(0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4), p2o5teor = c(0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17), k2omer = c(0.104,
0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104,
0.102, 0.102, 0.102, 0.102, 0.102, 0.102, 0.102, 0.102, 0.102,
0.102, 0.384, 0.384, 0.384, 0.384, 0.384, 0.384, 0.384, 0.384,
0.384, 0.384, 0.211, 0.211, 0.211, 0.211, 0.211, 0.211, 0.211,
0.211, 0.211, 0.211, 0.18, 0.18, 0.18, 0.18, 0.18, 0.18, 0.18,
0.18, 0.18, 0.18, 0.266, 0.266, 0.266, 0.266, 0.266, 0.266, 0.266,
0.266, 0.266, 0.266, 0.26, 0.26, 0.26, 0.26, 0.26, 0.26, 0.26,
0.26, 0.26, 0.26), p2o5mer = c(0.167, 0.167, 0.167, 0.167, 0.167,
0.167, 0.167, 0.167, 0.167, 0.167, 0.165, 0.165, 0.165, 0.165,
0.165, 0.165, 0.165, 0.165, 0.165, 0.165, 0.171, 0.171, 0.171,
0.171, 0.171, 0.171, 0.171, 0.171, 0.171, 0.171, 0.16, 0.16,
0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.164, 0.164,
0.164, 0.164, 0.164, 0.164, 0.164, 0.164, 0.164, 0.164, 0.162,
0.162, 0.162, 0.162, 0.162, 0.162, 0.162, 0.162, 0.162, 0.162,
0.165, 0.165, 0.165, 0.165, 0.165, 0.165, 0.165, 0.165, 0.165,
0.165), al2o3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.017, 0.017,
0.017, 0.017, 0.017, 0.017, 0.017, 0.017, 0.017, 0.017, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0.006, 0.006, 0.006, 0.006, 0.006, 0.006,
0.006, 0.006, 0.006, 0.006, 0.025, 0.025, 0.025, 0.025, 0.025,
0.025, 0.025, 0.025, 0.025, 0.025, 0.019, 0.019, 0.019, 0.019,
0.019, 0.019, 0.019, 0.019, 0.019, 0.019, 0.016, 0.016, 0.016,
0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016), tskut = c(900L,
900L, 900L, 900L, 900L, 950L, 950L, 950L, 950L, 950L, 900L, 900L,
900L, 900L, 900L, 950L, 950L, 950L, 950L, 950L, 900L, 900L, 900L,
900L, 900L, 950L, 950L, 950L, 950L, 950L, 900L, 900L, 900L, 900L,
900L, 950L, 950L, 950L, 950L, 950L, 900L, 900L, 900L, 900L, 900L,
950L, 950L, 950L, 950L, 950L, 900L, 900L, 900L, 900L, 900L, 950L,
950L, 950L, 950L, 950L, 900L, 900L, 900L, 900L, 900L, 950L, 950L,
950L, 950L, 950L), doba = c(15L, 30L, 60L, 120L, 240L, 15L, 30L,
60L, 120L, 240L, 15L, 30L, 60L, 120L, 240L, 15L, 30L, 60L, 120L,
240L, 15L, 30L, 60L, 120L, 240L, 15L, 30L, 60L, 120L, 240L, 15L,
30L, 60L, 120L, 240L, 15L, 30L, 60L, 120L, 240L, 15L, 30L, 60L,
120L, 240L, 15L, 30L, 60L, 120L, 240L, 15L, 30L, 60L, 120L, 240L,
15L, 30L, 60L, 120L, 240L, 15L, 30L, 60L, 120L, 240L, 15L, 30L,
60L, 120L, 240L), rutrtg = c(16.4, 87.1, 96.6, 95, 96.5, 34.9,
98.5, 98.3, 99.3, 99.8, 25.9, 71.3, 79.8, 84.9, 89.6, 43.3, 83.2,
87.2, 93.4, 93.5, 10.1, 33, 53.8, 30.5, 34.2, 17.7, 50.9, 69.1,
86.6, 92.4, 20.3, 76.1, 87.6, 89.7, 94.7, 17, 44.6, 43.4, 46.7,
54.7, 10, 42.6, 76.9, 54.2, 75.6, 29, 80.8, 96.2, 84.2, 85.7,
8.9, 41.3, 56.9, 43.9, 46.5, 36.6, 71.8, 83.5, 75.5, 80.4, 9.1,
26.6, 40.7, 36, 56.3, 34.5, 69.2, 73.3, 74.7, 79.5), barvivost = c(888,
1611, 1663, 1681, 1706, 1287, 1341, 1519, 1645, 1689, 1176, 1562,
1665, 1669, 1731, 1375, 1694, 1718, 1769, 1783, 954, 1428, 1568,
1476, 1521, 927, 1641, 1717, 1796, 1848, 1158, 1629, 1746, 1743,
1792, 1090, 1508, 1620, 1636, 1689, 932, 1442, 1689, 1538, 1731,
1139, 1760, 1822, 1864, 1868, 894, 1443, 1629, 1594, 1666, 1572,
1705, 1811, 1774, 1806, 796, 1371, 1512, 1515, 1636, 1352, 1690,
1771, 1778, 1849), podton = c(10L, 6L, 5L, 7L, 7L, 9L, -7L, -3L,
3L, 3L, 12L, 10L, 12L, 11L, 10L, 10L, 11L, 8L, 10L, 8L, 15L,
15L, 16L, 16L, 16L, 10L, 14L, 12L, 13L, 9L, 15L, 14L, 15L, 15L,
13L, 12L, 12L, 12L, 12L, 10L, 13L, 12L, 13L, 15L, 12L, 14L, 13L,
8L, 7L, 6L, 14L, 16L, 15L, 15L, 13L, 15L, 13L, 8L, 9L, 7L, 13L,
16L, 16L, 16L, 13L, 14L, 13L, 8L, 8L, 5L), lpas = c(45.21, 52.42,
52.94, 53.12, 53.37, 49.19, 49.73, 51.5, 52.76, 53.2, 48.08,
51.93, 52.96, 53, 53.62, 50.07, 53.25, 53.49, 54, 54.13, 45.87,
50.6, 51.99, 51.07, 51.52, 45.6, 52.72, 53.48, 54.26, 54.78,
47.9, 52.6, 53.77, 53.74, 54.22, 47.23, 51.39, 52.51, 52.67,
53.2, 45.65, 50.74, 53.2, 51.69, 53.62, 47.71, 53.91, 54.52,
54.94, 54.98, 45.27, 50.75, 52.6, 52.25, 52.97, 52.03, 53.36,
54.41, 54.04, 54.36, 44.3, 50.03, 51.43, 51.46, 52.67, 49.84,
53.21, 54.02, 54.08, 54.79), apas = c(1.05, 0.46, 0.48, 0.45,
0.39, 0.6, 0.82, 0.59, 0.4, 0.33, 0.7, 0.47, 0.27, 0.31, 0.18,
0.54, 0.28, 0.22, 0.1, 0.07, 0.89, 0.57, 0.43, 0.47, 0.38, 0.94,
0.3, 0.14, -0.03, -0.01, 0.67, 0.4, 0.12, 0.17, -0.02, 0.82,
0.46, 0.33, 0.31, 0.26, 0.93, 0.5, 0.24, 0.35, 0.15, 0.72, 0.15,
0.17, 0.12, 0.16, 0.96, 0.54, 0.24, 0.28, 0.27, 0.38, 0.18, 0.16,
0.21, 0.22, 1.13, 0.66, 0.41, 0.41, 0.31, 0.54, 0.18, 0.22, 0.23,
0.19), bpas = c(-0.02, 0.87, 0.91, 0.51, 0.59, 0.13, 3.45, 2.53,
1.45, 1.36, -0.31, 0.03, -0.42, -0.13, 0.03, -0.04, -0.28, 0.46,
0.09, 0.47, -0.92, -0.95, -1.11, -1.1, -1.11, 0.02, -0.7, -0.39,
-0.5, 0.18, -1, -0.81, -0.9, -0.95, -0.68, -0.44, -0.44, -0.33,
-0.33, -0.02, -0.63, -0.48, -0.68, -0.92, -0.36, -0.84, -0.53,
0.43, 0.61, 0.83, -0.72, -1.11, -0.97, -1.06, -0.62, -0.9, -0.56,
0.35, 0.14, 0.64, -0.59, -1.24, -1.13, -1.28, -0.52, -0.83, -0.51,
0.47, 0.4, 0.97), vodivost = c(868, 185.3, 95.5, 106.3, 87.8,
514, 86.4, 95.3, 62.2, 56.4, 1192, 570, 497, 484, 448, 930, 571,
503, 453, 832, 1966, 969, 661, 1288, 678, 3054, 597, 477, 431,
347, 1095, 430, 401, 371, 332, 2250, 1392, 1205, 1173, 1142,
1508, 710, 479, 686, 529, 1017, 520, 417, 466, 488, 2240, 908,
692, 808, 784, 724, 698, 557, 773, 698, 1784, 848, 800, 777,
644, 883, 609, 702, 628, 716), zaverage = c(311.7, 348.1, 336,
321, 325.2, 327.6, 518.3, 415, 353.1, 355.4, 258.3, 286.2, 265.1,
288.7, 308.5, 258.5, 271.6, 311.8, 283.7, 298.3, 209.5, 227,
231, 219.9, 228.1, 245.1, 254.9, 270.6, 265.6, 297.6, 231.8,
256.9, 247.5, 246.7, 258.1, 223.3, 246.2, 253.2, 255.6, 275.8,
250.4, 256.6, 248.6, 223.5, 254.2, 254, 293.8, 296.6, 299.6,
310.1, 225.4, 228.6, 237.4, 228.7, 238, 239.5, 250.5, 288.4,
303.7, 301.1, 230.1, 222, 225.8, 222.9, 255.4, 236.8, 261.6,
292.9, 295.7, 318.7), k2o.f = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), .Label = c("low", "standard", "high", "extreme"), class = "factor"),
int = structure(c(1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L,
1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 4L, 4L,
8L, 8L, 8L, 8L, 8L, 2L, 2L, 2L, 2L, 2L, 6L, 6L, 6L, 6L, 6L,
9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L, 10L, 10L, 10L,
10L, 10L, 12L, 12L, 12L, 12L, 12L, 3L, 3L, 3L, 3L, 3L, 7L,
7L, 7L, 7L, 7L), .Label = c("low/900/3", "standard/900/3",
"high/900/3", "extreme/900/3", "low/950/3", "standard/950/3",
"high/950/3", "extreme/950/3", "standard/900/6", "high/900/6",
"standard/950/6", "high/950/6"), class = c("ordered", "factor"
), scores = structure(c(3, 6, 3, 3, 6, 3, 3, 6, 3, 3, 6,
3), .Dim = 12L, .Dimnames = list(c("low/900/3", "standard/900/6",
"standard/900/3", "high/900/3", "high/900/6", "extreme/900/3",
"low/950/3", "standard/950/6", "standard/950/3", "high/950/3",
"high/950/6", "extreme/950/3"))))), .Names = c("vzorek",
"promot", "teplota", "k2oteor", "p2o5teor", "k2omer", "p2o5mer",
"al2o3", "tskut", "doba", "rutrtg", "barvivost", "podton", "lpas",
"apas", "bpas", "vodivost", "zaverage", "k2o.f", "int"), class = c("nfnGroupedData",
"nfGroupedData", "groupedData", "data.frame"), row.names = c(NA,
70L), formula = rutrtg ~ doba | int, FUN = function (x)
max(x, na.rm = TRUE), order.groups = TRUE)

> --
> Sent from my phone. Please excuse my brevity.
>
> On December 27, 2016 11:39:29 PM PST, PIKAL Petr
> <petr.pikal at precheza.cz> wrote:
> >Hi Jeff.
> >
> >Yes, if it had been reproducible I would not post it as I had known
> >solution myself. (Uff, I hope I used this conditional clause
> >correctly).
> >
> >OTOH your suggestion works and seems to arrive to desired result even
> >that you said you do not know what I am talking about. R (and this
> >smart community) sometimes surprise me even after quite a long time
> >experience.
> >
> >Thanks.
> >Petr
> >
> >> -----Original Message-----
> >> From: Jeff Newmiller [mailto:jdnewmil at dcn.davis.ca.us]
> >> Sent: Tuesday, December 27, 2016 4:21 PM
> >> To: PIKAL Petr <petr.pikal at precheza.cz>; r-help mailing list
> ><r-help at r-
> >> project.org>
> >> Subject: Re: [R] offset in nlme
> >>
> >> Not reproducible. Tsk!
> >>
> >> I really don't know what you are taking about,  but some ideas are:
> >>
> >> mySSasymp <- function( doba, Asym, lrc ) {
> >>   SSasymp(doba, Asym, 0, lrc)
> >> }
> >>
> >> Another idea is to use log( time ) rather than time.
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> On December 27, 2016 6:47:12 AM PST, PIKAL Petr
> ><petr.pikal at precheza.cz>
> >> wrote:
> >> >Dear all
> >> >
> >> >I would like to fit SSasymp model to some data by nlme. I did not
> >find
> >> >any clue how to set one of parameters to fixed constant value
> >(R0=0).
> >> >
> >> >One suitable way could be to use SSlogis as it has one parameter
> >zero,
> >> >however it is not correct AFAIK logistics is defined from -Inf to
> >Inf
> >> >and my x value is time, starting from 0.
> >> >
> >> >The only option I found is to define my own growth function which is
> >> >constrained by some fixed starting point. Does anybody know other
> >way
> >> >around? Like persuading nlme not optimize R0 and be happy with the
> >> >value set in the function call.
> >> >
> >> >something like
> >> >
> >> >nlsList(rutrtg ~ SSasymp(doba, Asym, R0, lrc), data=rutil.g,
> >> >start=c(Asym=100, R0= 10, lrc=-2), offset=c(R0=10))
> >> >
> >> >which obviously does not work.
> >> >
> >> >I could put some data but it is more a matter of nlme or other R
> >> >functions then real data.
> >> >
> >> >Looking forward to some answer.
> >> >Happy New year 2017
> >> >
> >> >Petr Pikal
> >> >

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
```