[R] function problem

2009-07-31 Thread RRRRRRRRRR!

I have a series of columns that need to be evaluated in various tables. I
need to apply a function in the following manner somers2(name1,name2). name1
is a vector of x inputs for the function which correspond to a vector of y
inputs in name2.

y<-rep(c(3,4,5,8),6)
z<-rep(c(23,24,25,26,27,28),4)
name1<-sprintf("Pred_pres_%s_indpdt[,%s,,]",x,y)
name2<-sprintf("population[,%s]",z)


rank<-function(i,j){

for(i in name1){
for(j in name2){
somers2(i,j)
}}}

Thanks

Robert
-- 
View this message in context: 
http://www.nabble.com/function-problem-tp24759253p24759253.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.


Re: [R] function problem

2009-07-31 Thread RRRRRRRRRR!

I am sorry I should have stated the whole problem:

I appreciate all the help I have received from this list and also not being
flamed because I am new to R. Many of my problems are in automation so far.

I am trying to create multiple objects that are outputs of functions. Here
are the tasks:

aGAM<-somers2(Pred_pres_a_indpdt[,3,,],population[,23])
aGBM<-somers2(Pred_pres_a_indpdt[,4,,],population[,23])
cGLM<-somers2(Pred_pres_a_indpdt[,5,,],population[,23])
cRF<-somers2(Pred_pres_a_indpdt[,8,,],population[,23])

bGAM<-somers2(Pred_pres_b_indpdt[,3,,],population[,24])
bGBM<-somers2(Pred_pres_b_indpdt[,4,,],population[,24])
bGLM<-somers2(Pred_pres_b_indpdt[,5,,],population[,24])
bRF<-somers2(Pred_pres_b_indpdt[,8,,],population[,24])

...and so on through the letter f.

so the variables (x,y,z in this example) are as follows:

xGAM<-somers2(Pred_pres_x_indpdt[,y,,],population[,z])

the GAM, GBM, GLM, and RF are stored in a column y in "Pred_pres_x_indpdt."
x is denoting a species, which corresponds to column z in "population," so
a:f == 23:28

~~~
This may be pushing it, but it would be great if I could get all of these in
a matrix of dim[1,96]

Here is what I have so far:

x <- c("a","b","c","d","e","f")
nums <- c(23:28)

rank<-function(x){

for(y in nums){

xGAM<-somers2(Pred_pres_x_indpdt[,3,,],population[,y])
xGBM<-somers2(Pred_pres_x_indpdt[,4,,],population[,y])
xGLM<-somers2(Pred_pres_x_indpdt[,5,,],population[,y])
xRF<-somers2(Pred_pres_x_indpdt[,8,,],population[,y])

rank(x)

}}

#for each species, there is 16 columns of output, so a total of 96 columns
is needed

x_matrix<-matrix(c(xGAM[1:2],Evaluation.results.TSS[[1]][1,3:4],xGBM[1:2],Evaluation.results.TSS[[1]][2,3:4],
xGLM[1:2],Evaluation.results.TSS[[1]][3,3:4],xRF[1:2],Evaluation.results.TSS[[1]][4,3:4]),
nrow=1,ncol=16,
dimnames=list(c(""),
c("x_gam_AUC", "x_gam_Dxy","x_gam_TSS","x_gam_Cutoff","x_gbm_AUC",
"x_gbm_Dxy","x_gbm_TSS","x_gbm_Cutoff",
"x_glm_AUC", "x_glm_Dxy","x_glm_TSS","x_glm_Cutoff","x_rf_AUC",
"x_rf_Dxy","x_rf_TSS","x_rf_Cutoff")))


Thanks again for helping me out



Steve Lianoglou-6 wrote:
> 
> Hi,
> 
> On Jul 31, 2009, at 12:25 PM, RR! wrote:
> 
>> I have a series of columns that need to be evaluated in various  
>> tables. I
>> need to apply a function in the following manner  
>> somers2(name1,name2). name1
>> is a vector of x inputs for the function which correspond to a  
>> vector of y
>> inputs in name2.
>>
>> y<-rep(c(3,4,5,8),6)
>> z<-rep(c(23,24,25,26,27,28),4)
>> name1<-sprintf("Pred_pres_%s_indpdt[,%s,,]",x,y)
>> name2<-sprintf("population[,%s]",z)
>>
>>
>> rank<-function(i,j){
>>
>>  for(i in name1){
>>  for(j in name2){
>> somers2(i,j)
>> }}}
> 
> You're missing a value for x, so I'm finding it hard to understand  
> what you're trying to do, exactly. From your double for loop, it seems  
> like you just want to compute the function over all vals in X, and  
> each x against all Y.
> 
> Does this help?
> 
> R> x <- LETTERS[1:3]
> R> y <- LETTERS[10:15]
> R> all.vals <- expand.grid(x,y, stringsAsFactors=F)
> R> all.vals[1:3,]
>Var1 Var2
> 1AJ
> 2BJ
> 3CJ
> 
> R> ans <- lapply(seq(nrow(all.vals)), function(i) paste(all.vals[i,1],  
> all.vals[i,2], sep='(*)'))
> R> ans[1:3]
> [[1]]
> [1] "A(*)J"
> 
> [[2]]
> [1] "B(*)J"
> 
> [[3]]
> [1] "C(*)J"
> 
> -steve
> 
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>|  Memorial Sloan-Kettering Cancer Center
>|  Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/function-problem-tp24759253p24759625.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] automation question

2009-07-31 Thread RRRRRRRRRR!

I have columns in two tables that need to be compared in order to get a
statistic. The function calculating the statistic is somers2. Here are the
two columns I must calculate, row by row. 

  name1   name2
1  Pred_pres_a_indpdt[,3,,] population[,23]
2  Pred_pres_b_indpdt[,3,,] population[,24]
3  Pred_pres_c_indpdt[,3,,] population[,25]
4  Pred_pres_d_indpdt[,3,,] population[,26]
5  Pred_pres_e_indpdt[,3,,] population[,27]
6  Pred_pres_f_indpdt[,3,,] population[,28]
7  Pred_pres_a_indpdt[,4,,] population[,23]
8  Pred_pres_b_indpdt[,4,,] population[,24]
9  Pred_pres_c_indpdt[,4,,] population[,25]
10 Pred_pres_d_indpdt[,4,,] population[,26]
11 Pred_pres_e_indpdt[,4,,] population[,27]
12 Pred_pres_f_indpdt[,4,,] population[,28]
13 Pred_pres_a_indpdt[,5,,] population[,23]
14 Pred_pres_b_indpdt[,5,,] population[,24]
15 Pred_pres_c_indpdt[,5,,] population[,25]
16 Pred_pres_d_indpdt[,5,,] population[,26]
17 Pred_pres_e_indpdt[,5,,] population[,27]
18 Pred_pres_f_indpdt[,5,,] population[,28]
19 Pred_pres_a_indpdt[,8,,] population[,23]
20 Pred_pres_b_indpdt[,8,,] population[,24]
21 Pred_pres_c_indpdt[,8,,] population[,25]
22 Pred_pres_d_indpdt[,8,,] population[,26]
23 Pred_pres_e_indpdt[,8,,] population[,27]
24 Pred_pres_f_indpdt[,8,,] population[,28]

the somers2 function works like this:

somers2(x, y)

for example:   somers2(Pred_pres_a_indpdt[,3,,], population[,23])

so somers2 is calculated for each row, with column 1 as x, column 2 as y.
Is there anyway to automate this?

-R




-- 
View this message in context: 
http://www.nabble.com/automation-question-tp24761918p24761918.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] another automation question

2009-07-31 Thread RRRRRRRRRR!

This code works:

x<-letters[1:6]
ycols<-23:28
xcols<-rep(c(3,4,5,8),each=length(ycols))

somertime<-function(i,j)somers2(Pred_pres_a_indpdt[,i,,], population[,j])
results<-mapply(somertime,xcols,ycols)



How can I make variable "h" work?

x<-letters[1:6]
ycols<-23:28
xcols<-rep(c(3,4,5,8),each=length(ycols))

somertime<-function(h,i,j)somers2(Pred_pres_h_indpdt[,i,,], population[,j])
results<-mapply(somertime,x,xcols,ycols)

-R
-- 
View this message in context: 
http://www.nabble.com/another-automation-question-tp24763017p24763017.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.