0

I am trying to plot 3 regression lines for 3 components in the data estimated via flexmix package. However, when I try to plot predicted values for the first component, the result is a messy graph with lines connecting to each other.

This is what I get

These are my codes:

m_1 <- flexmix(x ~ y + z, data=set2, cluster=clstr)
yhat <-fitted(m_1)
plot(x, y, options=...)
lines(x, yhat[,1], options=...)

Online I found some hints about > order() with no result

reorder <- order(yhat[,1])

lines(x[reorder], yhat[,1][reorder], options=...)

It results in a continuous line that looks like a time series with high volatility.

The other two components are working fine. Any idea on how to solve this?

patL
  • 2,259
  • 1
  • 17
  • 38
userIT8991
  • 47
  • 8
  • Maybe it is not useful to predict but just use the coefficient estimad using an abline ? Could give a reproductible example ? – Rémi Coulaud May 22 '19 at 11:22

1 Answers1

0

The solution is here I think :

http://pages.mtu.edu/~shanem/psy5220/daily/Day19/Mixture_of_regressions.html

Rémi Coulaud
  • 1,684
  • 1
  • 8
  • 19