2

I'm having some problems trying to plot multiple reliability functions in one single graph from a inverse gaussian distirbution. I need the functions to be lines, and all I got is points, when trying to set type="l", it happens to be a mess drawing mulitle lines everywhere.

Here is the code

library("statmod")
x<-rinvgauss(90,0.000471176,0.0000191925)
y<-rinvgauss(90,0.000732085,0.000002982015)
z<-rinvgauss(180,0.000286672,0.00000116771)

den<-pinvgauss(x,0.000471176,0.0000191925)
dens<-pinvgauss(y,0.000732085,0.000002982015)
densi<-pinvgauss(z,0.000286672,0.00000116771)

rel<-1-den
reli<-1-dens
relia<-1-densi

plot(x,rel, xlim=c(0,0.002), col="red")
points(y,reli, col="blue")
points(z,relia, col="black")

I would really appreciate any help on this!

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
LuisRD
  • 25
  • 5

2 Answers2

2

The problem is your x, y, z values aren't sorted...

library("statmod")
x <- sort(rinvgauss(90,0.000471176,0.0000191925))
y <- sort(rinvgauss(90,0.000732085,0.000002982015))
z <- sort(rinvgauss(180,0.000286672,0.00000116771))

den   <- pinvgauss(x,0.000471176,0.0000191925)
dens  <- pinvgauss(y,0.000732085,0.000002982015)
densi <- pinvgauss(z,0.000286672,0.00000116771)

rel   <- 1-den
reli  <- 1-dens
relia <- 1-densi

plot(x,rel, xlim=c(0,0.002), col="red", type="l")
lines(y,reli, col="blue")
lines(z,relia, col="black")
smci
  • 32,567
  • 20
  • 113
  • 146
Ron Jensen
  • 641
  • 7
  • 20
2

Your values weren't sorted. This should work:

    x<-sort(rinvgauss(90,0.000471176,0.0000191925))
    y<-sort(rinvgauss(90,0.000732085,0.000002982015))
    z<-sort(rinvgauss(180,0.000286672,0.00000116771))

den<-sort(pinvgauss(x,0.000471176,0.0000191925))
dens<-sort(pinvgauss(y,0.000732085,0.000002982015))
densi<-sort(pinvgauss(z,0.000286672,0.00000116771))

rel<-1-den
reli<-1-dens
relia<-1-densi

plot(x,rel, xlim=c(0,0.002), col="red",type="l")
lines(y,reli, col="blue")
lines(z,relia, col="black")
Julian Wittische
  • 1,219
  • 14
  • 22