[R-sig-ME] varIdent warnings in nlme
Cole, Tim
tim.cole at ucl.ac.uk
Fri Sep 23 15:50:55 CEST 2016
I'm getting lots of warnings:
In conLin$Xy * varWeights(object) :
longer object length is not a multiple of shorter object length
when using varIdent for weights in nlme. I see that the problem has been flagged several times since 2004, but I'm an optimist and I wondered if there was a workaround or fix. Despite the warnings, the results seem to be correct.
If anyone has any experience of this I'd be interested to hear.
Here are some examples from my CRAN R sitar growth curves package, with data from the heights database. I've unpacked the sitar call to show the nlme call. I'm not too bothered about the singularities, which look to be data-driven, just the warnings.
if (!require(sitar)) install.packages('sitar')
library(sitar)
data(heights)
names(heights)[2:3] <- c('x', 'y')
heights$x <- scale(heights$x, scale=FALSE)
df <- 6
knots <- with(heights, quantile(x, (1:(df-1))/df))
bounds <- with(heights, range(x) + abs(0.04) * c(-1,1) * diff(range(x)))
start <- with(heights, lm(y ~ ns(x, knots=knots, Bound=bounds)))$coef
start <- c(start[c(2:(df+1), 1)], 0, 0)
fitnlme <- function(x,s1,s2,s3,s4,s5,s6,a,b,c) {
as.vector(a +
(as.matrix(cbind(s1,s2,s3,s4,s5,s6)) * as.matrix(ns((x-b) * exp(c),
knots=knots, Bound=bounds))) %*% matrix(rep(1,df), ncol=1))
}
test <- function(...) {
# NLME CALL HERE
invisible(nlme(y ~ fitnlme(x,s1,s2,s3,s4,s5,s6,a,b,c), data = heights,
fixed = s1+s2+s3+s4+s5+s6+a+b+c ~ 1,
random = a+b+c ~ 1 | id, start = start, ...))
}
test() # THE MODEL WITHOUT weights WORKS FINE
heights$wt1 <- factor(as.numeric(heights$id) > 6) # split 63:61 GROUPING FACTOR FOR varIdent
heights$wt2 <- factor(heights$id == 12) # split 120:4 ALTERNATIVE GROUPING FACTOR
ratio <- 1e3 # c(0.5, 1:5, 10^(1:6)) # DIFFERENT RATIOS FOR value AND fixed IN varIdent
var <- c(`TRUE`=ratio)
# RESULTS HERE FOR DIFFERENT FORMS OF varIdent AND DIFFERENT VALUES OF ratio
test(weights=Initialize(varIdent(form=~1|wt1), heights)) # ok
test(weights=Initialize(varIdent(form=~1|wt2), heights)) # Singularity
test(weights=Initialize(varIdent(var, form=~1|wt1), heights)) # ok
test(weights=Initialize(varIdent(var, form=~1|wt2), heights)) # Singularity, all ratios
test(weights=Initialize(varIdent(form=~1|wt1, fixed=var), heights)) # warnings / Singularity depending on ratio
test(weights=Initialize(varIdent(form=~1|wt2, fixed=var), heights)) # warnings
Thanks if you've read this far.
Best wishes,
Tim Cole
---
Tim.cole at ucl.ac.uk<mailto:Tim.cole at ucl.ac.uk> Phone +44(0)20 7905 2666 Fax +44(0)20 7905 2381
Population, Policy and Practice Programme
UCL Great Ormond Street Institute of Child Health, London WC1N 1EH, UK
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list