It may not be sufficiently easy to understand, but the warning message

"Some predictor variables are on very different scales: consider rescaling"

does actually tell you how you can make the model fit.  summary(my.df)
shows that direction ranges from -1 to 1, while distance ranges from 100 to
68813.

Either of the following work fine:

cs. <- function(x) scale(x,scale=TRUE,center=TRUE)
my.fit2 = glmer(response ~ cs.(distance) + direction + (1|id), data = my.df,
family = Gamma())

or

my.fit3 = glmer(response ~ I(distance/1e6) + direction + (1|id), data =
my.df,
family = Gamma())





On Sat, Jul 5, 2014 at 1:33 PM, Nimrod Rubinstein <
nimrod.rubinstein@gmail.com> wrote:

> Hi,
>
> I have these data:
>
> my.df = structure(list(response = c(0.516074952, 0.580012258, 0.5488396,
> 0.514189282, 0.541119544, 0.534505123, 0.51646652, 0.509050733,
> 0.518528396, 0.518612368, 0.633614104, 0.571088979, 0.707287635,
> 0.551960442, 0.628561587, 0.636816662, 0.84273424, 0.791398785,
> 0.564327876, 0.572247664, 0.542536414, 0.817166116, 0.598312173,
> 0.549507424, 0.648524073, 0.548890252, 0.525518275, 0.55938954,
> 0.632503362, 0.525381357, 0.52893369), distance = c(558648, 384605, 357615,
> 313157, 268367, 201775, 166657, 145176, 143358, 92778, 80661, 64350, 33872,
> 30410, 10309, 100, 12670, 51609, 66232, 72622, 76022, 89428, 92727, 131314,
> 160023, 197924, 227711, 280067, 285519, 413874, 688813), direction = c(-1,
> -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), id = c("12", "12", "7.3", "7.3", "6.2",
> "7.4", "2.3", "7.5", "2.3", "1", "7.4", "7.3", "7.1", "18", "7.1", "17",
> "7.5", "X", "2.1", "7.4", "10", "6.2", "2.1", "1", "2.1", "11.1", "7.5",
> "15.1", "15.1", "2.3", "15.2"), color = c("aquamarine3", "aquamarine3",
> "aquamarine3", "aquamarine3", "orange1", "orange1", "lemonchiffon",
> "goldenrod1", "lemonchiffon", "wheat4", "orange1", "aquamarine3",
> "darkslategrey", "wheat4", "darkslategrey", "cyan", "goldenrod1",
> "goldenrod1", "orange1", "orange1", "navajowhite1", "orange1", "orange1",
> "wheat4", "orange1", "tomato", "goldenrod1", "navajowhite1",
> "navajowhite1", "lemonchiffon", "darkred")), .Names = c("response",
> "distance", "direction", "id", "color"), row.names = c(NA, -31L ), class =
> "data.frame")
>
> And I would like to fit a mixed effects model where the response is
> my.df$response, the fixed effects are: as.numeric(my.df$distance) and
> as.factor(my.df$direction), and the random effect isas.factor(my.df$id).
>
> The attached plot (plot(x = my.df$distance*as.numeric(my.df$direction), y =
> my.df$response, col = my.df$color, lwd = 2, xlab = "Direction", ylab =
> "Response"))
>
> gives me the sense that a generalized linear mixed effects model with a
> Gamma family is appropriate, but I may be wrong.
>
> Trying to fit such a model with:
> library(lme4)
> #set my.df$direction and my.df$id as factors
> my.df$direction = as.factor(my.df$direction)
> my.df$id = as.factor(my.df$id)
> my.fit = glmer(response ~ distance + direction + (1|id), data = my.df,
> family = Gamma())
>
> I get many lines with a message of this sort:
> (bG) nan @ pos 23: y= 0.549507; mu=-0.0772004; wt=1; y/mu=-7.11793;
> log(y/mu) =1.#QNAN
>
> And at the end this message:
> Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in
> pwrssUpdate In addition: Warning message:
> In checkScaleX(X, ctrl = control) : Some predictor variables are on very
> different scales: consider rescaling
>
> Are my data that messy that a glmer with a gamma family cannot be fitted to
> them or am I doing something wrong?
>
> _______________________________________________
> R-sig-mixed-models@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>

	[[alternative HTML version deleted]]

