[R] Multiple, multiple regressions...

Thomas Levine thomas.levine at gmail.com
Thu Oct 28 03:31:59 CEST 2010


Write a function() that does everything you want to do for one
regression, then run that on all of them. It'll look something like
this.

library(car)

myreg=function(X,v1,v2,v3,v4,v5) {
reg=lm(X ~ v1 + v2 + v3 + v4 + v5)
crPlots(reg)
}

Then run the function a lot, maybe in a loop or with sapply().

Tom

2010/10/26 Duncan, Adam <adam.duncan at credit-suisse.com>:
>
> Caveats and disclaimers:
> I am quite happy to undertake self-teaching if directed to a relevant
> prior posting and welcome such
> direction. I have programming and statistical training/experience which
> I would characterize as Masters level.
> Thank you for reading and replying to this post. It is very much
> appreciated.
>
> ---begin problem description
>
> I have a large data set that I have imported to R from excel via the
> RODBC library.
> The data set contains information about 4 factors for 22 currency pairs
> per factor. That is,
> the first 22 columns are, say, the spot exchange rate. The next 22
> columns are, say, the interest
> rate differential, and so on. There is a singular vector in the data set
> at the end bringing the total
> number of columns to 89.
>
> The objective is to run a multiple regression of the form:
>
> X ~ v1 + v3 + v3 + v4 + v5
>
> and display a plot of the residuals. The tough part is that I need to
> run this multiple regression 22 times, once for
> each currency pair. I would like to produce a graphic that contains,
> say, the first 8 residual plots on one page. Ultimately,
> I would like to produce standardized residuals for each regression, and
> rank them in order of the absolute value of
> the most recent residual.
>
> I have created matrix variables to house each of the 22 currency
> variables. Here is a result of examining the
> matrix variable "idiff" that holds the interest rate differentials:
>
>  head(idiffm,5)
>  EURINTDIF GBPINTDIF JPYINTDIF CHFINTDIF CADINTDIF AUDINTDIF NZDINTDIF
> SEKINTDIF NOKINTDIF EURJPYINTDIF EURGBPINTDIF
> 1  -0.02562  -0.16125   0.47000   0.56542  -0.23625   3.64625   2.57875
> 0.16875  -1.82625      0.44438      0.13563
> 2  -0.01125  -0.13813   0.45188   0.54521  -0.25979   3.68062   2.60312
> 0.13688  -1.88812      0.44063      0.12688
> 3   0.01313  -0.11875   0.42875   0.51667  -0.28583   3.70500   2.62750
> 0.11750  -1.91750      0.44188      0.13188
> 4   0.01313  -0.11875   0.42875   0.51667  -0.28583   3.70500   2.62750
> 0.11750  -1.91750      0.44188      0.13188
> 5   0.01313  -0.11875   0.42875   0.51667  -0.28583   3.70500   2.62750
> 0.11750  -1.91750      0.44188      0.13188
>  EURCHFINTDIF EURCADINTDIF EURAUDINTDIF EURNZDINTDIF EURSEKINTDIF
> EURNOKINTDIF NOKSEKINTDIF CADJPYINTDIF AUDJPYINTDIF
> 1      0.53980      1.50000     -3.67187     -2.60437      0.14313
> -1.85187        1.995      0.70625      4.11625
> 2      0.53396      1.50167     -3.69187     -2.61437      0.12563
> -1.89937        2.025      0.71167      4.13250
> 3      0.52980      1.49833     -3.69187     -2.61437      0.13063
> -1.90437        2.035      0.71458      4.13375
> 4      0.52980      1.49833     -3.69187     -2.61437      0.13063
> -1.90437        2.035      0.71458      4.13375
> 5      0.52980      1.49833     -3.69187     -2.61437      0.13063
> -1.90437        2.035      0.71458      4.13375
>  GBPJPYINTDIF NZDJPYINTDIF
> 1      0.30875      3.04875
> 2      0.31375      3.05500
> 3      0.31000      3.05625
> 4      0.31000      3.05625
> 5      0.31000      3.05625
>
> ---end problem description
>
> Can someone point me to a script that might be useful in running all 22
> of these multiple regressions and plotting the residuals
> (or at least the first 8-10) in a singular graphic?
>
> Thank you very much for the help.
>
> Best regards,
>
> -adam duncan
> adam.duncan at credit-suisse.com
>
> ===============================================================================
> Please access the attached hyperlink for an important el...{{dropped:4}}
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list