I am going to teach econometrics soon and as some of you might know, there is this concept of regression where we try to fit a a best plot on the data.
I know how to make a graph with just one point (as shown below). But is there a simpler way to plot some random points around a straight line?
Basically I would like to create a scatterplot such that the points are random on the graph but not too much. In other words points are on a line but say there is a random error in $y$. Also, can I control the variance of this error with values of $x$?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[xscale=3, yscale=1.5]
\draw [thick, <->] (0,1) -- (0,0) -- (1,0);
\node [below right] at (1,0) {$x$};
14
\node [left] at (0,1) {$y$};
\draw[fill] (.4,.6) circle [radius=.5pt];
\end{tikzpicture}
\end{document}
create on use/y/.style={create col/expr={(0.6*\thisrow{x}+130)+(\thisrow{x}<80?3:10)*rand}}. The key part there is the expression(\thisrow{x}<80?3:10)*rand, which means "If x is less than 80, use a spread of 3, else use a spread of 10". – Jake Jun 06 '14 at 11:27