# [R] NLME regression with weights, syntax in r

LEPREVOST Florian (SNCF / DIR TECHNOLOGIES INNOVATION ET PROJETS GROUPE / IR DIR RECHERCHE -MEV) |@|eprevo@t @end|ng |rom @nc|@|r
Fri Oct 28 14:52:04 CEST 2022

```Hi all,

I found this (very) old post which had a similar problem but went without an answer (https://stat.ethz.ch/pipermail/r-help/2004-October/058325.html)

I am trying to fit a power curve to model some observations in an nlme. However, I know some observations to be less reliable than others (reliability of each OBSID reflected in the WEIV in the dummy data), relatively independent of variance, and I quantified this beforehand and wish to include it as weights in my model. Moreover, I know a part of my variance is correlated with my independent variable so I cannot use directly the variance as weights.

This is my model:

coeffs_start = lm(log(DEPV)~log(INDV), filter(testdummy10,DEPV!=0))\$coefficients

nlme_fit <- nlme(DEPV ~ a*INDV^b,

data = testdummy10,

fixed=a+b~ 1,

random = a~ 1,

groups = ~ PARTID,

start = c(a=exp(coeffs_start[1]), b=coeffs_start[2]),

verbose = F,

method="REML",

weights=varFixed(~WEIV))

This is some sample dummy data (I know it is not a great fit but it's fake data anyway) : https://github.com/FlorianLeprevost/dummydata/blob/main/testdummy10.csv

This runs well without the "weights" argument, but when I add it I get this error and I am not sure why because I believe it is the correct syntax:

Error in recalc.varFunc(object[[i]], conLin) :

dims [product 52] do not match the length of object [220]

In conLin\$Xy * varWeights(object) :

longer object length is not a multiple of shorter object length

Best

Florian

-------
Ce message et toutes les pièces jointes sont établis à l'intention exclusive de ses destinataires et sont confidentiels. L'intégrité de ce message n'étant pas assurée sur Internet, la SNCF ne peut être tenue responsable des altérations qui pourraient se produire sur son contenu. Toute publication, utilisation, reproduction, ou diffusion, même partielle, non autorisée préalablement par la SNCF, est strictement interdite. Si vous n'êtes pas le destinataire de ce message, merci d'en avertir immédiatement l'expéditeur et de le détruire.
-------
This message and any attachments are intended solely for the addressees and are confidential. SNCF may not be held responsible for their contents whose accuracy and completeness cannot be guaranteed over the Internet. Unauthorized use, disclosure, distribution, copying, or any part thereof is strictly prohibited. If you are not the intended recipient of this message, please notify the sender immediately and delete it.

[[alternative HTML version deleted]]

```