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.
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?
The solution is here I think :
http://pages.mtu.edu/~shanem/psy5220/daily/Day19/Mixture_of_regressions.html