[R] superimpose graphs

From: 苏江东Su Jiangdong <sujiangdong_at_gmail.com>
Date: Sat, 16 Apr 2011 18:17:54 +0100


Hi there,

I have a data frame DF of over 600 people's short term trade data in time order. Below is the simplified structure of the data.

         id     invest     payout

[1] 1 10 -1
[2] 1 33 33
[3] 1 20 -5
[4] 2 200 33
[5] 2 33 -20
[6] 3 5 -5
[7] 3 5 -5

id is each person's id. Each person have invested many times in the sampling period, in temporal order.

What I want to check is the correlation between invest and payout.

  1. How do I run the regression for each person, with the "invest" being devided by the mean or medium of the person's "invest"?
  2. How do I plot a graph with y axis being invest/mean(invest) and x axis being payout, all 600 people's dots superimposed on one graph?

I tried to use

for (i in 1:(dim (DF)[1]-1))
 {
if (DF[i,1]=DF[i+1,1]) id.lm <- lm(invest ~ payput, data=DF) }

But I don't know how to superimpose graphs onto each other.

Thanks a lot!

Su

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 16 Apr 2011 - 23:59:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Apr 2011 - 03:10:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive