[R] R compilation

2009-01-28 Thread Attiglah, Mama

Hi Mates, 
I have a very long R code that needs to go to production but my portfolio 
managers do not use R language and the software is not supported by my bank. 
Is there any way I can compile the code to an executable file and make it 
usable to my portfolio managers who have no knowledge at all of R? 

Thanks 

Mama 
 - 
Mama Attiglah, PhD
Quantitative Strategist
Liability Driven Investment 
State Street Global Advisors 
25 Bank Street, London E14 5NU 
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax) 
Authorised and regulated by the Financial Services Authority.
State Street Global Advisors Limited, a company registered in England with 
company number 2509928
and VAT number 5576591 81 and whose registered office is...{{dropped:12}}

__
R-help@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.


Re: [R] re stricting points in a data frame

2008-01-30 Thread Attiglah, Mama
Let's A = expand.grid(xk1=xk1,xk2=xk2)

B = A[A[,1] %in% x1 & A[,2] %in% x2, ]

Should in principle produce the desired result.

Mama 


-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of dxc13
Sent: 30 January 2008 16:20
To: r-help@r-project.org
Subject: [R] re stricting points in a data frame


useR's,

Consider some variables and a data frame of points:
x1 <- c(1,2,3)
x2 <- c(3,4,5)
xk1 <- seq(min(x1)-.5, max(x1)+.5,.5)
xk2 <- seq(min(x2)-.5, max(x2)+.5,.5)
expand.grid(xk1=xk1,xk2=xk2)

   xk1 xk2
1  0.5 2.5
2  1.0 2.5
3  1.5 2.5
4  2.0 2.5
5  2.5 2.5
6  3.0 2.5
7  3.5 2.5
...
46 2.0 5.5
47 2.5 5.5
48 3.0 5.5
49 3.5 5.5

I want to restrict the data frame to only contain points that are within
the
x1 and x2 range.  So for this example, only points between 1 and 3
should be
kept for x1 and values between 3 and 5 should be kept for x2.  This
condition needs to be satisfied for both points, not just one of them;
i.e.,
if an x1 point satisfies this, but its corresponding x2 point does not,
then
this point should be removed.
Does anyone know a way to do this, in general, for any data frame? 
Hope this is not confusing.
Thanks in advance
dxc13 
-- 
View this message in context:
http://www.nabble.com/restricting-points-in-a-data-frame-tp15184381p1518
4381.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.

__
R-help@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.


[R] Non linear optimising with a linear equality constraints

2008-01-30 Thread Attiglah, Mama



Hi room, 
Is there any R package that solves a non linear objective pb, with
linear equality constraint? 

A simple example   
a =c (2, 5, 6, 7, 2) 

b = c (7, 1, 4, 5, 6) 

a and b are vectors of length 5

minimise f(x, a) = sum( (x-a)^2)  such that  sum( x*b) = 50. 

where x is the control variable. 
N.B. 
For your info, I believe the structure of these solvers:
nlm, nlimb, lp, optim, optimize, constrOptim, solveLP, solve.QP, etc... 
are not appropriate for it.
Solve.QP is the closest to a quad pb with inequality constraints which
when changed to two inequality constraints produces a degenerated
solution due to the fact that the Amat matrix's rows are dependent.

Thanks

Mama 



-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

__
R-help@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.

__
R-help@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.


Re: [R] Concatenate xyplots

2008-01-30 Thread Attiglah, Mama

Hi room, 
Is there any R package that solves a non linear objective pb, with
linear equality constraint? 

A simple example   
a =c (2, 5, 6, 7, 2) 

b = c (7, 1, 4, 5, 6) 

a and b are vectors of length 5

minimise f(x, a) = sum( (x-a)^2)  such that  sum( x*b) = 50. 

where x is the control variable. 
N.B. 
For your info, I believe the structure of these solvers:
nlm, nlimb, lp, optim, optimize, constrOptim, solveLP, solve.QP, etc... 
are not appropriate for it.
Solve.QP is the closest to a quad pb with inequality constraints which
when changed to two inequality constraints produces a degenerated
solution due to the fact that the Amat matrix's rows are dependent.

Thanks

Mama 



-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

__
R-help@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.


Re: [R] Multiplying each row of a big matrix with a vector

2008-01-30 Thread Attiglah, Mama
I understood that you only need to multiply each row of Ret by the
vector Pos but it seems that you would like to sum the resulting vector
element in order to have a vector of length 500. 
That is merely the matrix multiplication in R!!! 
i.e.  Ret %*% Pos. 
Am I getting the question wrong? 

Mama 

-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Attiglah, Mama
Sent: 30 January 2008 11:32
To: Megh Dal; [EMAIL PROTECTED]
Subject: Re: [R] Multiplying each row of a big matrix with a vector


Ret= matrix(sample( 1:1000, 500*9), nrow=500, ncol=9)


Pos= c(  2593419  ,2130220,  6198197,  1673888,  198 , 1784732 ,
2052120 ,-7490228 ,-5275000)


Solution = Ret * matrix( rep(Pos, 500), nrow=500, byrow=TRUE)
Use the element-wise multiplication rather than a matrix multiplication.
Hope this helps.
Mama 

-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Megh Dal
Sent: 30 January 2008 07:20
To: [EMAIL PROTECTED]
Subject: [R] Multiplying each row of a big matrix with a vector

I have a big matrix 'ret'. I want to multiply each row of it with a 2nd
vector 'pos', resulting result, I want to save in a vector named 'port'.
I wrote following code:
   
  > pos
[1]  2593419  2130220  6198197  1673888  198  1784732  2052120
-7490228 -5275000

   
  > dim(ret)
[1] 500   9

  > fu# user defined function
function(x)
   {
fu = x %*% t(pos)
   }
port = apply(ret, 1, fu)

  > dim(port)
[1]  81 500

  My desire is to get port as a vector with length 500. However I am not
getting that?
   
  Can anyone tell me how to correct that? 
   
  Regards,
   

   
-

[[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.

__
R-help@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.


Re: [R] Multiplying each row of a big matrix with a vector

2008-01-30 Thread Attiglah, Mama

Ret= matrix(sample( 1:1000, 500*9), nrow=500, ncol=9)


Pos= c(  2593419  ,2130220,  6198197,  1673888,  198 , 1784732 ,
2052120 ,-7490228 ,-5275000)


Solution = Ret * matrix( rep(Pos, 500), nrow=500, byrow=TRUE)
Use the element-wise multiplication rather than a matrix multiplication.
Hope this helps.
Mama 

-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Megh Dal
Sent: 30 January 2008 07:20
To: [EMAIL PROTECTED]
Subject: [R] Multiplying each row of a big matrix with a vector

I have a big matrix 'ret'. I want to multiply each row of it with a 2nd
vector 'pos', resulting result, I want to save in a vector named 'port'.
I wrote following code:
   
  > pos
[1]  2593419  2130220  6198197  1673888  198  1784732  2052120
-7490228 -5275000

   
  > dim(ret)
[1] 500   9

  > fu# user defined function
function(x)
   {
fu = x %*% t(pos)
   }
port = apply(ret, 1, fu)

  > dim(port)
[1]  81 500

  My desire is to get port as a vector with length 500. However I am not
getting that?
   
  Can anyone tell me how to correct that? 
   
  Regards,
   

   
-

[[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.


Re: [R] How to get two y-axises in a bar plot?

2008-01-29 Thread Attiglah, Mama

Try this 

X = rbind(y1, y2)
colnames(X) = as.character(x)

barplot( X, density=c(35,40), col=c("red","blue"), beside=FALSE)
barplot( X, density=c(35,40), col=c("red","blue"), beside=TRUE)


Alternatively, 
barplot( y1, ylim = c(0, max(y1,y2)), col="blue", beside=FALSE)

par(new=TRUE)

barplot( y2, ylim = c(0, max(y1,y2)), col="red", beside=FALSE,
names.arg=as.character(x))


Mama

-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Gustaf Granath
Sent: 29 January 2008 16:15
To: r-help@r-project.org
Subject: [R] How to get two y-axises in a bar plot?

Hi,
I have measured two response variables (y1, y2) at each treatment level 
(x = 0, 1.5 or 3). Now I would like to show the y1 and y2 against x in a

bar plot. However, y1 and y2 differ in scale so I need two y-axises, one

on the left side and one on the right side (and I dont want to 
standardize my responses). This is fairly easy if you want to show 
points,lines etc, but gets more complicated with bars.Although these 
kind of bar graphs are quite common, I have found very limited 
information about how to do them in R. I have been struggling with the 
barplot() command. My problem is that the bars for y1 and y2 end up at 
the same place (blocking each other) and not beside each other when I 
use par(new=TRUE). Is there a way to separate them so y1 and y2 are 
placed beside each other at each x level, or is this easier to do this 
with lattice?? I would also like to add error bars but I guess that 
should not be a problem.

For code and data, see below.

Cheers,

Gustaf Granath, phd student

My code so far:
#Creating data
c(6.34,13.38,17.87)->y1
c(0.85,1.88,2.33)->y2
c(0,1.5,3)->x
cbind(y1,y2,x)->mydata
data.frame(mydata)->mydata
with(mydata, tapply(y1,x,mean))->mean.y1
with(mydata, tapply(y2,x,mean))->mean.y2
#Barplot
par(mar=c(5,4,4,4)+0,1)
barplot(mean.y1,density=1,las=1)
par(new=T)
barplot(mean.y2,density=3,angle=3,axes=F)
axis(4,las=1)

__
R-help@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.

__
R-help@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.


Re: [R] how to generate sequence "a" - "z"

2008-01-29 Thread Attiglah, Mama

> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
"r" "s" "t" "u" "v" "w" "x" "y" "z"
> LETTERS
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q"
"R" "S" "T" "U" "V" "W" "X" "Y" "Z"
>
Hope that will help.

Mama 

-
Mama Attiglah, PhD
Advanced Research Center
Quantitative Research Analyst
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Bernd Weiss
Sent: 29 January 2008 12:43
To: skestin; [EMAIL PROTECTED]
Subject: Re: [R] how to generate sequence "a" - "z"

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

skestin schrieb:
| I suppose it's very simple but I can't find the way to generate a
sequence of
| characters, e.g. from "a" to "z".
| Could you please help me with this?

?letters
letters


HTH,

B.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHnx9IUsbvfbd00+ERAuasAKCYIZ9KC4c3NoDFfkdDP0MyZckinwCbBQv7
CX249me9JFbVlWNPy/mDtV0=
=Vaea
-END PGP SIGNATURE-

__
R-help@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.

__
R-help@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.


Re: [R] pivot table in R

2008-01-29 Thread Attiglah, Mama
A = read.table("clipboard", header=TRUE)
> A
  sex   age region no_of_accidents
1   F young  north  10
2   F young  south  12
3   F   old  north   5
4   F   old  south   7
5   M young  north  24
6   M young  south  30
7   M   old  north  12
8   M   old  south  17





sum(A$no_of_accidents[which( A$sex=="F")])

should give you the required sum. 

You have to remember that sex, age and region are Factors with their
respective levels and no_of_accidents is a numeric vector.

Do str( A) to see their type.
Hope that helps.

Mama 

-
Mama Attiglah, PhD
Advanced Research Center 
Quantitative Research Analyst 
State Street Bank
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 29 January 2008 12:05
To: r-help@r-project.org
Subject: [R] pivot table in R

Hello,

I'm struggling with an elementary problem with R. I have a simple data 
frame such as this one giving the number of accidents subdivided by sex,

age and region.

sex age region  no_of_accidents

F   young   north   10
F   young   south   12
F   old north   5
F   old south   7
M   young   north   24
M   young   south   30
M   old north   12
M   old south   17

and I would like to build a pivot table, e.g. obtaining the sum of the 
number of accidents for each sex:

sex age region  no_of_accidents

F   (any)   (any)   34
M   (any)   (any)   83

but I can't seem to obtain this result simply in R, except by embarking
in 
complicated "for" loops.

I have checked the documentation on such functions as "table()" and the 
documentation on "An introduction to R" but couldn't solve the problem. 
Could you please help me with this?

Cheers

Pete


PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS E-MAIL

For Aon's standard conditions associated with this e-mail please visit
http://www.aon.com/uk/en/email-footer/aon-limited.jsp
Aon Limited
Registered Office: 8 Devonshire Square, London EC2M 4PL
Registered in London No. 210725 . VAT Registration No. 480 8401 48

Aon Limited is authorised and regulated by the Financial Services
Authority in respect of insurance mediation activities only.

[[alternative HTML version deleted]]

__
R-help@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.


[R] Compiling R code

2008-01-29 Thread Attiglah, Mama
Hi all, 
I am struggling to compile a massive R code that I have written through
some years, aiming to provide automated investment strategies to my
Portfolio Managers. You may ask me why do I not rewrite the code in C or
C++; the answer is it is really massive and that will take me lots of
time. 
The pb is I will be moving from one team to another therefore I want to
make it an exec program that the PMs can run in their investment
universe without my help.
I am using the very long method described in the R extension doc which
is taking me time as each block of the code needs to be carefully
evaluated.  
I researched about the RCC project aiming to do the job but it seems to
me that the compiler is not yet available.
Is anyone experienced in compiling R code to an exec file or had a
similar experience in the past? 
Thanks 
Mama 

-
Mama Attiglah, PhD
Advanced Research Center 
Quantitative Research Analyst 
State Street Bank 
+44(0)20 7698 6290 (Direct Line)
+44 (0)207 004 2968 (Direct Fax)
Please visit our Web site at 
www.ssga.com


[[alternative HTML version deleted]]

__
R-help@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.