Is it possible to modify a mix_norm object before plotting it?

13 views Asked by At

This may be a very silly question, and maybe even a bug, but I can't find a way around it. I have a "Normal Mixture" object in R, which I created using the function norMix from the package nor1mix. When I plot it, it shows me mixed distribution, and a normal one based on the same data, all good.

The problem is, before plotting it, I want to multiply it by a number. I can do this, but when I try to plot the modified object I get:

Error in dnorMixL(x, x = xout, n = n) : 'obj' must be a 'Normal Mixture' object!

Despite the object still being a Normal Mixture.

There is a small difference between the structure of both objects though, this is for the original one:

 > str(mix_list[16][[1]])
 'norMix' num [1:2, 1:3] 0.906 2.125 0.354 0.151 0.923 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:3] "mu" "sigma" "w"
 - attr(*, "name")= chr "NM2.0.92_0.40.2"

And for the modified:

 > str(mix_list[16][[1]]*10)
 'norMix' num [1:2, 1:3] 9.06 21.25 3.54 1.51 9.23 ...
 - attr(*, "name")= chr "NM2.0.92_0.40.2"
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:3] "mu" "sigma" "w"

The order is different for some reason.

Is there any way to multiply norMix objects without altering their structure or to change the structure afterwards? I would be very thankful if someone could help me.

Another possibility would be to apply the transformation to the data from which the norMix object was created, but that is not possible either because for some reason, with big numbers it results in an error.

0

There are 0 answers