2
I need to adjust a non-linear function through routines nls
or nlsLM
, However, my data generates heterocedastic waste when calculated with these routines, which does not allow me to adjust directly through the sum of waste squares
I already have the equation that makes the residues homocedastic, but I do not know how to make the routine use this form to calculate the residues in place of the direct calculation of (observed-expected) 2
So Jose, do you have anything ready? Any excerpts from the code? Could tbm explain better what you mean by
resíduos heterocedásticos
andresíduos homocedásticos
This seems to me to have more to do with Linear Regression -- Mathematics.– MarceloBoni
Hello, @Marcelobonifazio! I’m using the nlsLM function directly, just input my dataset and have it run. Heterocedastic residues occur when the difference between the observed and the expected (residues) presents a trend in their distribution over x. Routines {nls} and {nlsLM} adjust the model by minimizing the square of the waste, need to change this part of the code
– José Ricardo
Joseph, the code of
nls
is open and can be seen by typingnls
on the R console. If you want to edit you can recreate the function by doingnls <- código mostrado...
However, this should not be easy. There are other ways to fix heterocedasticity by changing the model and not code, are sure that’s what you need to do?– Daniel Falbel
@Danielfalbel, I need to change the code because my data matrix has this problem. I even opened the nls code, but I could not identify the part that calculates the waste to make the change. You can tell me this?
– José Ricardo
I don’t think it pays to change the code for cost-effectiveness. Why don’t you try adjusting a model with a function for variance tbm? The function
gnls
adjusts models with a function for the variance passed to the argumentweights
– Daniel Falbel
I tried to use the argument
weights
andvarFunc
in functiongnls
but I couldn’t make it work. I’m new to R and sometimes I get into simple problems. What is needed is to calculate the residues as follows: Resid = (observed - expected)/(Ax b). Parameters a and b I provide manually according to the data matrix used.– José Ricardo
what is x in your formula?
– Daniel Falbel
x is my independent variable present in my data matrix. It occurs like this: I am relating weight according to the length of a species (x = length, y = weight), the variability in weight increases as individuals get bigger, so I divide the residues by an equation that describes this increase in variability (in this specific case, a power equation), thus eliminating heterocedasticity.
– José Ricardo