1

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}
  • 1
  • Using a bivariate normal distribution with a high ratio between standard deviations would create a random scatter that seems to be around a line. But why not simply do the actual regression process, i.e. find a database of points and calculate the regression. What I understood from your question is that you want to do the reverse process of regression (have a line, want set of point in which the line present their regression), or am I wrong? – Pouya Jun 6 '14 at 10:22
  • @Jake: Thanks very much for the useful link. I have an even extended version of the question. How to make the points scatter even more at some part keeping the line same (case 1) and for two different lines (case 2). Or in other words say in the example in the linked question, how to make the dots after weight 80 `more away' from the line? – Abhimanyu Arora Jun 6 '14 at 11:15
  • 1
    @AbhimanyuArora: In that example, you could use 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 6 '14 at 11:27
  • 1
    @Jake Want to write an answer? – Torbjørn T. Jul 5 '14 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.