[R] apply to a matrix and insert in the middle of an array

2011-10-09 Thread Maas James Dr (MED)
If possible I'd like to produce a function that applies a formula to a column 
in a matrix (essentially calculating the mse) and then inserts it between 
values of a an array ...

confusing I know, here is an example of what I'm trying to accomplish:

## create a matrix
(a - matrix(c(3,6,4,8,5,9,12,15),nrow=4))
## get the mean of all columns
(b - apply(a,2,mean))
## calculate the mse of column 1
(c - (sd(a[,1])/sqrt(length(a[,1]
## calculate the mse of column 2
(d - (sd(a[,2])/sqrt(length(a[,2]
## now create a new vector with each mean value and its corresponding
## mse right beside it
(e - c(b[1],c,b[2],d))

Would anyone have any suggestions how to accomplish this using an apply 
statement?

Thanks a bunch,

J
===
Dr. Jim Maas
University of East Anglia

__
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] procedure Power in module Math

2011-09-04 Thread Maas James Dr (MED)

Hi All,

I'm attempting to compile and run a BUGS model using OpenBUGS from R and 
getting this message.  I've googled around not found much, it may well 
be a problem with OpenBUGS and not R.  Any suggestions or clues as to 
how to find the problem would be welcome.  I'm wondering if I'm missing a 
library on Linux or something?

** Sorry something went wrong in procedure Power in module Math **


Thanks a bunch,

Jim


===
Dr. Jim Maas
University of East Anglia

__
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] extract value from mer object ?

2011-05-17 Thread Maas James Dr (MED)

What is the easiest way to extract a value from a 'mer' object from glmer?  The 
first I need is the 
trtpair Std.Dev.   which in this case is 0.17542?

I've managed to get the fixed effects numbers from 
summary(fednmaout)@coeffs

but no luck with the Random effects stuff.

TIA

Jim


 fednmaout
Linear mixed model fit by REML 
Formula: lor ~ as.factor(t2) + as.factor(t3) + (1 | trtpair) 
   AIC   BIC logLik deviance REMLdev
 97.17 107.6 -43.5883.12   87.17
Random effects:
 Groups   NameVariance Std.Dev.
 trtpair  (Intercept) 0.030771 0.17542 
 Residual 0.230785 0.48040 
Number of obs: 60, groups: trtpair, 3

Fixed effects:
   Estimate Std. Error t value
(Intercept)  0.3752 0.3563   1.053
as.factor(t2)1  -0.1677 0.2909  -0.576
as.factor(t3)1   0.1796 0.2909   0.617

Correlation of Fixed Effects:
(Intr) a.(2)1
as.fctr(2)1 -0.816   
as.fctr(3)1 -0.816  0.500

===
Dr. Jim Maas
University of East Anglia

__
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] howto calculate column means in data frame

2011-04-10 Thread Maas James Dr (MED)
Long story short, I have a big iterative procedure that produces a long list of 
data.frames such as the one called
results here.  Is there an easy way to produce a similar list of data.frames 
comprised of the mean of each of the
columns in results, such that it ends up like the one I've shown in 
resultsmean below?

I've tried apply and lapply, still not got the correct arguments.  As usual, 
TIA.

Jim

 results
[[1]]
   nameLOR23   BIA23   MSE23  H0R23
1 0.222   -1.012228   -0.0959370.0356501.00
2 0.222   -0.8363000.0799910.0423220.75
3 0.222   -0.5186310.3976590.2145930.50


[[2]]
   nameLOR23   BIA23   MSE23  H0R23
1 0.2211122   -0.7246300.1916600.051308   1
2 0.2211122   -0.7818120.1344780.033872   1
3 0.2211122   -0.5221090.3941810.1646280.75


would like

 resultsmean
[[1]]
   nameLOR23   BIA23   MSE23  H0R23
1 0.222   -0.783330.12734 0.0971600.75

[[2]]
   nameLOR23   BIA23   MSE23  H0R23
1 0.2211122   -0.675660.2400  0.08266 0.916

===
Dr. Jim Maas
University of East Anglia

__
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] extract variance for random effects from mer object

2011-04-07 Thread Maas James Dr (MED)
I get an output from a glmer package, but would like to extract the variance of 
the Random effects, in this case called trtpair and the value is 0.

Can I extract it directly or do I need to do some further calculations on the 
mer object to get it?

Thanks

Jim

 class(fednmaout)
[1] mer
attr(,package)
[1] lme4
 fednmaout
Generalized linear mixed model fit by the Laplace approximation 
Formula: cbind(fednmadat$events, fednmadat$patnums - fednmadat$events) ~  
treat + tn + (1 | trtpair) 
   AIC   BIC logLik deviance
 84.01 153.1 -9.00618.01
Random effects:
 Groups  NameVariance Std.Dev.
 trtpair (Intercept)  00  
Number of obs: 60, groups: trtpair, 3

===
Dr. Jim Maas
University of East Anglia

__
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] save ordinary numerical calculations as pdf

2011-03-30 Thread Maas James Dr (MED)
I'd like to save some calculation outputs as a pdf, to incorporate with others 
in a document.  I've tried

pdf(filename)
name_of_object_to_output
dev.off()

but it doesn't seem to work, appears that this pdf function is for graphics?

Is there a way to output numerical objects to pdf?

Thanks

J

Dr. Jim Maas
University of East Anglia

__
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] creating character vector

2011-03-14 Thread Maas James Dr (MED)
Is there a way to convince R to create a character vector without using the 
quotes?

This works

ex1 -  c(first,second)

but when I try this it doesn't

ext - as.character(c(first,second))

it complains. I have many variables to put into character vectors so dispensing 
with the quotes would be useful.

Thanks

Jim


===
Dr. Jim Maas
University of East Anglia


[[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] creating list of lists

2011-03-12 Thread Maas James Dr (MED)
Question 1:
I have a long list of variable names such as

first - c(one,two,three)

and what I want to do is create a list of lists ... where the names of each of 
overall lists components are  one,two, and three.

This is the same result as 

second - list(one=list(),two=list(),three=list())

Is there a way to exploit lapply to convert a list such as first to a list of 
empty lists such as second?

Question 2:

In a parallel routine using foreach and doMPI have to put calcualted values 
into a list of lists such as 

list(one=one,
 two=two,
 three=three)

It uses the same (large) list of variable names as first in question 1.  Is 
there a simpler way to accomplish this with a lapply statement?


I've tried several permutations but no luck! Thanks a bunch.

Jim

===
Dr. Jim Maas
University of East Anglia

__
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] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread Maas James Dr (MED)
I'm attempting to sort a 3 dimensional array that looks like this
 x
, , 1
 [,1] [,2]
[1,]99
[2,]79
, , 2
 [,1] [,2]
[1,]65
[2,]46
, , 3
 [,1] [,2]
[1,]21
[2,]32

Such that it ends up like this 
 y
, , 1
 [,1] [,2]
[1,]21
[2,]32
, , 2
 [,1] [,2]
[1,]65
[2,]46
, , 3
 [,1] [,2]
[1,]99
[2,]79

I think this is sorting across the third dimension but several attempts using 
either the sort or apply functions have not worked.  Any and all suggestions 
most welcome.  Thanks

J

===
Dr. Jim Maas
University of East Anglia


[[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.


Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread Maas James Dr (MED)
Hi Rex,

Thanks, this is exactly what I want but have to do it with many big arrays ... 
thus if there were a way to do it with a vectorized function would it not be a 
lot more efficient?

Much appreciated!

J

Subject: RE: sort a 3 dimensional array across third dimension ?

Although I suggested to someone else that for-loops be avoided, they are
not in the inner loop in this code, and it's probably easier to
understand than some sort of apply:

a = array(round(100*runif(60)),dim=c(3,4,5))
a
for (i in 1:dim(a)[1])
 for (j in 1:dim(a)[2])
  a[i,j,] = sort(a[i,j,])
a

Is that what you want?

Subject: [R] sort a 3 dimensional array across third dimension ?

I'm attempting to sort a 3 dimensional array that looks like this
 x
, , 1
 [,1] [,2]
[1,]99
[2,]79
, , 2
 [,1] [,2]
[1,]65
[2,]46
, , 3
 [,1] [,2]
[1,]21
[2,]32

Such that it ends up like this 
 y
, , 1
 [,1] [,2]
[1,]21
[2,]32
, , 2
 [,1] [,2]
[1,]65
[2,]46
, , 3
 [,1] [,2]
[1,]99
[2,]79

I think this is sorting across the third dimension but several attempts
using either the sort or apply functions have not worked.  Any and all
suggestions most welcome.  Thanks

J

===
Dr. Jim Maas
University of East Anglia


__
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] removing lower and upper quantiles from an arry

2011-02-17 Thread Maas James Dr (MED)
I'm trying to work out the simplest way to remove the upper and lower 
quantiles, in this case upper and lower 25% from an array.  I can do it in two 
steps but when I try it in one, it fails.  Is there something simple missing 
from my syntax or are there other simple elegant way to accomplish this?  

Thanks

J

 i -1:20
 i2 - i[iquantile(i,.75)]
 i3 - i[iquantile(i,.25)]
 i4 - i[quantile(i,.25) i  quantile(i,.75)]
Error: unexpected '' in i4 - i[quantile(i,.25) i 
 
===
Dr. Jim Maas
University of East Anglia

__
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] does range of values in array include a third value?

2011-02-17 Thread Maas James Dr (MED)
I'm using the range command to get the minimum and maximum values of an array 
as in

x - range(array_y)

which gives me two values such as 

[1] -2 9

I need to be able to test if this range of values includes a third value.  For 
example I'd like to query 

1) does the range of -2 to 9 include 3, answer TRUE
2) does the range of -2 to 9 include -6, answer FALSE?

All values could be negative or positive.  Is there a R function that will test 
this or do I need to programme it?  I have searched but not found one.

Thanks

J

===
Dr. Jim Maas
University of East Anglia

__
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] does range of values in array include a third value?

2011-02-17 Thread Maas James Dr (MED)

I'm using the range command to get the minimum and maximum values of an array 
as in

x - range(array_y)

which gives me two values such as

[1] -2 9

I need to be able to test if this range of values includes a third value.  For 
example I'd like to query

1) does the range of -2 to 9 include 3, answer TRUE
2) does the range of -2 to 9 include -6, answer FALSE?

All values could be negative or positive.  Is there a R function that will test 
this or do I need to programme it?  I have searched but not found one.

Thanks

J

===
Dr. Jim Maas
University of East Anglia

[[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] Error in { : task 3 failed - NA/NaN argument

2011-01-30 Thread Maas James Dr (MED)
I'm attempting to run a rather complex routine that involves a few loops, and 
even some use of foreach and doMPI.  I just added another external loop and now 
get this error message.

Error in { : task 3 failed - NA/NaN argument

Is there a way to debug what is causing this error or where?  I really have no 
idea what task 3 is?

Thanks

Jim

===
Dr. Jim Maas
University of East Anglia
__
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] syntax for a list of components from a list

2011-01-20 Thread Maas James Dr (MED)
I'm attempting to generalise a function that reads individual list components, 
in this case they are matrices, and converts them into 3 dimensional array.  I 
can input each matrix individually, but want to do it for about 1,000 of them 
...

This works
array2 - abind(list1[[1]],list1[[2]],list1[[3]],along=3)

This doesn't
array2 - abind(list1[[1:3]],along=3)
This doesn't either
array2 - abind((list1[[1]]:(list1[[3]]),along=3)

Any thoughts how I can make this work for larger numbers?

Thanks

J

===
Dr. Jim Maas
University of East Anglia


[[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] combining matrices from a list into a multidimensional array

2011-01-19 Thread Maas James Dr (MED)
I get some results back from running an iterative analysis in the form of a 
list of matrices.  What I would like to do with this list is combine it such 
that all the similar components get combined into a multidimensional array.  If 
possible I'd like to put results[[1]]$resultmean and results[[2]]$resultmean 
into a 3x3x2 array, and also put results[[1]]$resultsd and 
results[[2]]$resultsd in a separate 3x3x2 array.  I'm sure this has been asked 
before, can someone point me in the right direction?

Thanks

J

 results
[[1]]
[[1]]$resultmean
 [,1] [,2]  [,3]
[1,] 1.00 0.768552 0.5743416
[2,] 1.307785 1.00 0.7500699
[3,] 1.747145 1.340882 1.000

[[1]]$resultsd
   [,1]   [,2]   [,3]
[1,] 0. 0.05495972 0.03390511
[2,] 0.09326529 0. 0.05718047
[3,] 0.10250638 0.10124427 0.


[[2]]
[[2]]$resultmean
 [,1]  [,2]  [,3]
[1,] 1.00 0.8280938 0.6170682
[2,] 1.213807 1.000 0.7472884
[3,] 1.631536 1.3479570 1.000

[[2]]$resultsd
   [,1]   [,2]   [,3]
[1,] 0. 0.05942645 0.05017175
[2,] 0.08719565 0. 0.06344005
[3,] 0.13576301 0.11621178 0.

===
Dr. Jim Maas
University of East Anglia

__
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] external R scripts

2010-11-10 Thread Maas James Dr (MED)
Is it possible to send data from an executing R script, to external R script 
files, on linux in this case, get that external R script to execute, and pass 
results back to the central script?  If so what commands should I be looking 
at?  I've googled for R and external, stuff like that but no luck.

The reason for the question is that I need to generate simulation data, then 
perform several different analyses on the same data set, then collate the 
results.  All individual analyses can be done sequentially, or perhaps more 
quickly by doing the individual analyses simultaneously if I pass them to 
external functions.

Thanks

J

===
Dr. Jim Maas
University of East Anglia


[[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] jags error message

2010-11-09 Thread Maas James Dr (MED)
Could anyone give me some clues as to the best way to debug this error message? 
 I think it is from the passing of variables back to R from the jags function 
which does Bayesian fitting.   The curious part for me is that the error 
messages seem random, yet the input data are always the same.  Any suggestions 
most welcome.

Thanks

J


Compiling model graph
   Resolving undeclared variables
   Allocating nodes
   Graph Size: 1604

  |++| 100%
  |**| 100%
Error : NA/NaN/Inf in foreign function call (arg 1)
In addition: There were 15 warnings (use warnings() to see them)


===
Dr. Jim Maas
University of East Anglia


[[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] getting all contrasts from glm

2010-10-22 Thread Maas James Dr (MED)
I'm using the following model to do an analysis

faicout - glm(cbind(events,patnums-events) ~  as.factor(treat) + 
as.factor(numtrial), family = binomial )

Is this example there are 4 treatments . In the glm object I can find the 
contrasts  of the main treats vs the first i.e. 2v1, 3v1 and 4v1 ... however I 
would like to get the complete set including 3v2, 4v2, and 4v3 ... along with 
the Std. Errors of all contrasts.  I've tried the contrasts argument of glm and 
attempted to use  model.matrix.default but with no luck.

Any suggestions how to get all treat contrasts with SE's?

Thanks

J

===
Dr. Jim Maas
University of East Anglia

[[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] create a list fails

2010-10-20 Thread Maas James Dr (MED)
I can not understand why this fails


 faicoutput2 - list(stuff21 = as.numeric(faicout$coefficients[2]),
+  stuff31=as.numeric(faicout$coefficients[3]),
+  stuff41=as.numeric(faicout$coefficients[4]),
+  stuff32=(stuff21-stuff31),
+  stuff42=(stuff21-stuff41),
+  stuff43=(stuff32-stuff42)
+  )
Error: object 'stuff21' not found

Why does it have to be found, exist previously ... it is being created?


But this works fine 

data - list(Ntrials =numtritot, Ncomparisons=2,
 treat=c(rep(1 ,N.trials[1,2]), rep(2,N.trials[1,3])),
 total.patientnums.trt1=dat2[ ,2],
 total.patientnums.trt23=dat2[ ,2],
 num.countstrt1=dat2[ ,5],
 num.countstrt23=dat2[ ,6] )


  





===
Dr. Jim Maas
University of East Anglia


[[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] rbind ing matrices and resetting column numbers

2010-10-14 Thread Maas James Dr (MED)
Sorry for the verbose example.  I want to row bind two matrices, and all works 
except I want the column labelled row to be sequential in the new matrix, 
shown as mat3 here, i.e. needs to be 1:6 and not 1:3 repeated twice.  Any 
suggestions?

Thanks

J

 colnm1 - c(row,ti,counti)
 colnm2 - c(row,tj,countj)
 mat1 - matrix(c(1,7,9,2,8,5,3,7,9),byrow=T,nrow=3)
 colnames(mat1) - colnm1
 mat1
 row ti counti
[1,]   1  7  9
[2,]   2  8  5
[3,]   3  7  9
 mat2 - matrix(c(1,5,3,2,6,8,3,3,7),byrow=T,nrow=3)
 colnames(mat2) - colnm2
 mat2
 row tj countj
[1,]   1  5  3
[2,]   2  6  8
[3,]   3  3  7
 mat3 - rbind(mat1,mat2)
 mat3
 row ti counti
[1,]   1  7  9
[2,]   2  8  5
[3,]   3  7  9
[4,]   1  5  3
[5,]   2  6  8
[6,]   3  3  7


===
Dr. Jim Maas
University of East Anglia


[[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] exponentiate elements of a whole matrix

2010-10-13 Thread Maas James Dr (MED)
I've tried hard to find a way to exponentiate each element of a whole matrix 
such that if I start with A

A = [ 2   3
  2   4]

I can get back B

B = [ 7.38   20.08
  7.38   54.60]

I've tried

B - exp(A) but no luck.

Thanks

J


===
Dr. Jim Maas
University of East Anglia

__
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] debugging

2010-10-07 Thread Maas James Dr (MED)
I'm attempting to learn how to use the debug function to find the values of 
some variables.  I've found a couple of documents describing the basics and 
they show examples that the debugger returns

Browse[1]


but for some reason when I follow the examples I get

Browse[2]


What is the 2 telling me ... why am I getting it and does it matter?

Thanks

J

===
Dr. Jim Maas
University of East Anglia


[[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] Error: attempt to apply non-function

2010-09-23 Thread Maas James Dr (MED)
This code worked fine for me, then did some cleaning up of formatting using ESS 
(Emacs) and now I get this error, no idea what is causing it, all the 
brackets/parentheses seem to be balanced.  What have I done wrong?

Thanks

Jim



p0.trial01 - 0.25
TruOR01 - 0.80
num.patients.01 - 50
num.trials.01 - 5
LOR01.het.in - 0.00
num.sims - 1

simLOR01 - vector(length=num.trials.01)
simLORSE01 - vector(length=num.trials.01)
simOR01 - vector(length=num.trials.01)
trialnum01 - vector(length=num.trials.01)

x0count - vector(length = num.trials.01)
x1count - vector(length = num.trials.01)

## Trial 1, comparison of treatment 1 with treatment 0

for (i in 1:num.trials.01) {

het01 - rnorm(1,0,LOR01.het.in)
log.odds.ratio.01 - log(TruOR01) + het01
odds.ratio.01 - exp (log.odds.ratio.01)

p1.trial01 - (p0.trial01 * odds.ratio.01) / (1 - p0.trial01 +
  (p0.trial01 * odds.ratio.01))

x0.trial01[i] -  rbinom(1,num.patients.01,p0.trial01)
x1.trial01[i] -  rbinom(1,num.patients.01,p1.trial01)

trialnum01[i] - paste ( c (trial01-), i, sep=)

simLOR01[i] - log (x1.trial01 * (num.patients.01 - x0.trial01) /
((num.patients.01 - x1.trial01) * x0.trial01))

simLORSE01[i] - sqrt ( (1/x0.trial01) + (1/(num.patients.01 -
 x0.trial01)) (1 / x1.trial01) 
+ (1 / (num.patients.01 -

   x1.trial01)))

simOR01[i] - (x1.trial01 * (num.patients.01 - x0.trial01) /
   ((num.patients.01 - x1.trial01) * x0.trial01))

}


## Output all results to a data.frame called results

results - data.frame (tn1 = trialnum01, SimOR01 = simOR01,
   SimLOR01 = simLOR01, SimLORSE01 = simLORSE01,
p1trial = p1.trial01, x0count, x1count )

set.seed(9321685)

results

rm(list=ls())


===
Dr. Jim Maas
University of East Anglia

[[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.


Re: [R] removing specific rows from array

2010-09-18 Thread Maas James Dr (MED)
Thanks Michael,

Quite an effort!  I failed to explain myself sufficiently clearly, what I need 
is for this if possible, to work with more than 4 treats, but still produce a 
matrix with all possible combinations of treatments (minus whichever treatment 
is in c1) in c2 and c3 but there would only be 1 comparison of 2 treatments ...

I managed to make two small changes to your code and it seems to work well.  
Now the vector treats can be any length.  Thanks a bunch.

Jim

treats - c(t0, t1, t2, t3,t4)
n - length(treats)
v - 2 #number of treatments per meta-analysis comparison
n2 - choose(n-1, v)
comb - matrix(, nrow=n*n2, ncol=v+1)
k - 1
for (i in 1:n) {
  comb[k:(k+n2-1), ] - cbind(treats[i], t(combn(treats[-i], v)))
  k - k + n2
} 



===
Dr. Jim Maas
University of East Anglia

From: Michael Bedward [michael.bedw...@gmail.com]
Sent: 18 September 2010 04:14
To: Maas James Dr (MED)
Cc: r-help@r-project.org
Subject: Re: [R] removing specific rows from array

Here's one way...

treats - c(t0, t1, t2, t3)
n - length(treats)
n2 - choose(n-1, n-2)
comb - matrix(, nrow=n*n2, ncol=n-1)
k - 1
for (i in 1:n) {
  comb[k:(k+n2-1), ] - cbind(treats[i], t(combn(treats[-i], n-2)))
  k - k + n2
}

It doesn't get any marks for conciseness but it should work :)

Michael


On 18 September 2010 00:51, Maas James Dr (MED) j.m...@uea.ac.uk wrote:
 I'm attempting to create an array of treatment comparisons for modelling data 
 generation.  This involves comparison of one treatment (c2) with another 
 (c3), relative to a common comparator (c1).

 Attached code gives me the correct array but need to remove duplicates.  
 Duplicates relate only to c2 and c3
 such that I need to remove

 r3 because c2 and c3 are same as r1 with c2 and c3 swapped
 r5 because c2 and c3 are same as r2 with c2 and c3 swapped
 r6 because c2 and c3 are same as r4 with c2 and c3 swapped
 r9 because c2 and c3 are same as r7 with c2 and c3 swapped
 r11 because c2 and c3 are same as r8 with c2 and c3 swapped
 .
 .
 .

 Any suggestions?

 Thanks

 Jim



 treats - c(t0,t1,t2,t3)
 (combs1 - permutations(length(treats),3,treats))
  [,1] [,2] [,3]
  [1,] t0 t1 t2
  [2,] t0 t1 t3
  [3,] t0 t2 t1
  [4,] t0 t2 t3
  [5,] t0 t3 t1
  [6,] t0 t3 t2
  [7,] t1 t0 t2
  [8,] t1 t0 t3
  [9,] t1 t2 t0
 [10,] t1 t2 t3
 [11,] t1 t3 t0
 [12,] t1 t3 t2
 [13,] t2 t0 t1
 [14,] t2 t0 t3
 [15,] t2 t1 t0
 [16,] t2 t1 t3
 [17,] t2 t3 t0
 [18,] t2 t3 t1
 [19,] t3 t0 t1
 [20,] t3 t0 t2
 [21,] t3 t1 t0
 [22,] t3 t1 t2
 [23,] t3 t2 t0
 [24,] t3 t2 t1



 ===
 Dr. Jim Maas
 University of East Anglia

 __
 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] removing specific rows from array

2010-09-17 Thread Maas James Dr (MED)
I'm attempting to create an array of treatment comparisons for modelling data 
generation.  This involves comparison of one treatment (c2) with another (c3), 
relative to a common comparator (c1).

Attached code gives me the correct array but need to remove duplicates.  
Duplicates relate only to c2 and c3
such that I need to remove 

r3 because c2 and c3 are same as r1 with c2 and c3 swapped 
r5 because c2 and c3 are same as r2 with c2 and c3 swapped 
r6 because c2 and c3 are same as r4 with c2 and c3 swapped
r9 because c2 and c3 are same as r7 with c2 and c3 swapped
r11 because c2 and c3 are same as r8 with c2 and c3 swapped
.
.
.

Any suggestions?

Thanks

Jim



 treats - c(t0,t1,t2,t3) 
 (combs1 - permutations(length(treats),3,treats))
  [,1] [,2] [,3]
 [1,] t0 t1 t2
 [2,] t0 t1 t3
 [3,] t0 t2 t1
 [4,] t0 t2 t3
 [5,] t0 t3 t1
 [6,] t0 t3 t2
 [7,] t1 t0 t2
 [8,] t1 t0 t3
 [9,] t1 t2 t0
[10,] t1 t2 t3
[11,] t1 t3 t0
[12,] t1 t3 t2
[13,] t2 t0 t1
[14,] t2 t0 t3
[15,] t2 t1 t0
[16,] t2 t1 t3
[17,] t2 t3 t0
[18,] t2 t3 t1
[19,] t3 t0 t1
[20,] t3 t0 t2
[21,] t3 t1 t0
[22,] t3 t1 t2
[23,] t3 t2 t0
[24,] t3 t2 t1



===
Dr. Jim Maas
University of East Anglia

__
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] using variable from for loop in naming new variables

2010-09-16 Thread Maas James Dr (MED)
Simple one here ... but can't get it to work ...

for (i in 1:4){
paste(stuff,[i]),sep=) - 3 + i
}

ls()
rm(list=ls())



I just want it to create 4 new variables called stuff1, stuff2, stuff3, stuff4 
with the corresponding assignments.  I realise that there are more elegant 
functions but this is just a model of a bigger situation.

Thanks

Jim


===
Dr. Jim Maas
University of East Anglia


[[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] pasting together 2 character arrays

2010-08-31 Thread Maas James Dr (MED)
If possible I would like to combine two different character arrays in 
combinations

Array1 - c(height,weight,age,sex)

Array2 - c(trt0,trt1,trt2)

I would like to combine these two character vectors to end up with such ...

Array3

height.trt0.trt1
height.trt0.trt2
weight.trt0.trt1
weight.trt0.trt2
age.trt0.trt1
age.trt0.trt2
sex.trt0.trt1
sex.trt0.trt2

I'm trying combinations of the combinations and paste functions, but no 
luck yet!
Any suggestions about most efficient approach most welcome.
Thanks

Jim

===
Dr. Jim Maas
University of East Anglia


[[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] multiple assignments ?

2010-08-24 Thread Maas James Dr (MED)
Simple one, have read and googled, still no luck!

I want to create several empty vectors all of the same length.

I would like multiple empty vectors (vec1, vec2, vec3) and want to create them 
all in one line.

I've tried

vec1,vec2,vec3 - vector(length=5)
and
c(vec1,vec2,vec3) - vector(length=5)

and several other attempts but nothing seems to work ... suggestions?

Thanks

Jim

===
Dr. Jim Maas
University of East Anglia


[[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] output values from within a function

2010-08-20 Thread Maas James Dr (MED)
Is it possible to get R to output the value of an expression, that is being 
calculated within a function?  I've attached a very simple example but for more 
complicated ones would like to be able to debug by seeing what the value of 
specific expressions are each time it cycles through a loop that executes the 
expression.  I'm relatively new to this so there may be much simpler more 
elegant ways to do it.

For example, is there a command I can put within the function funct01 that 
will output the value of z1 to the screen?

Thanks

Jim

==
## Practice file to try out evaluations

y - 5

(x - y^2)

funct01 - function (x,y) {

z1 - x + y
z2 - x * y
z3 - x^y

results - data.frame (z1=z1, z2=z2, z3=z3)
return(results)

}

funct01(7,9)


===
Dr. Jim Maas
University of East Anglia
Norwich, UK
NR4 7TJ

[[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] combinations

2010-08-18 Thread Maas James Dr (MED)
I would appreciate any suggestions on which function to use to write subsequent 
functions analysing combinations of treatments.

This refers to experimental trials of medical treatments.  I want to write 
routines to analyse various comparisons (combinations)

So  if 5 treatments are available (t01, t02, t03, t04 and t05) I want to 
write a general routine that works out all possible combinations, without 
repeats.  The other complication is that I want to be able to designate any one 
of the treatments as the common comparator such that all other treatments are 
compared to it.

For example, if I designate t04 as the common comparator then I want it to give 
me back some sort of vector or matrix with results

t01, t04
t02, t04
t03, t04
t05, t04

In my research I've found functions such as combinations and permutations in 
gtools, and also choose().  I suspect these could be coerced to provide the 
correct output but I may be missing a specific, or more flexible package that 
will produce this.

Any suggestions most welcome.

Thanks

Jim

===
Dr. Jim Maas
University of East Anglia
Norwich, UK

[[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] adding a row of names to data.frame

2010-07-05 Thread Maas James Dr (MED)
Relative noob here, I have a data.frame and simply want to add an explicit 
column of names in column 1 of the form
trial_number01 for row 1, trial_number02 for row 2  etc.  It is simply 
for visual purposes and to explain data to others.  I've tried
Using row.names and other but still no luck, am sure it has been covered but I 
can't find it, can you please point me in the right direction?

Thanks

Jim


===
Dr. Jim Maas
University of East Anglia
Norwich, UK


[[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.