[R] [R-pkgs] package JMbayes -- version 0.5-0

2014-01-17 Thread D. Rizopoulos
*** Apologies for cross posting ***

Dear Colleagues, Dear R-users,

I would like to announce the release of the new version of package 
JMbayes available from CRAN (http://CRAN.R-project.org/package=JMbayes). 
This package fits joint models for longitudinal and time-to-event data 
under a Bayesian approach using MCMC. These models are applicable in 
mainly two settings. First, when focus is on the survival outcome and we 
wish to account for the effect of an endogenous (aka internal) 
time-dependent covariates measured with error. Second, when focus is on 
the longitudinal outcome and we wish to correct for nonrandom dropout.

Some basic features of the new version:

* The MCMC in now implemented with efficient custom-made code and no 
longer relies on JAGS, OpenBUGS or WinBUGS.

* The user can now specify her own density function for the longitudinal 
responses using argument 'densLong' (default is the normal pdf). Among 
others, this allows to fit joint models with categorical and 
left-censored longitudinal responses and robust joint models with 
Student's-t error terms. In addition, using the 'df.RE' argument, the 
user can also change the distribution of the random effects from 
multivariate normal to a multivariate Student's-t with prespecified 
degrees of freedom.

* The user has now the option to define custom transformation functions 
for the terms of the longitudinal submodel that enter into the linear 
predictor of the survival submodel (argument 'transFun'). For example, 
interactions terms, nonlinear terms (polynomials, splines), etc.

* The baseline hazard is now only estimated using B-splines (penalized 
(default) or regression).

* Dynamic predictions:

   - function survfitJM.JMbayes(), which computes dynamic survival 
probabilities, is now faster;

   - the new generic function aucJM() calculates time-dependent AUCs for 
joint models;

   - the new generic function dynCJM() calculates a dynamic 
discrimination index (weighted average of time-dependent AUCs) for joint 
models;

   - the new generic function prederrJM() calculates prediction errors 
for joint models;

   - the new function bma.combine() combines predictions using Bayesian 
model averaging; posterior model weights can be calculated using 
logLik.JMbayes() and marglogLik().

* a method has been added for the xtable() generic from package xtable 
for producing a LaTeX table with the results of the joint model.

* Backward-incompatible version; the aforementioned changes require 
refitting joint models that have been fitted with previous versions.


As always, any kind of feedback (e.g., questions, suggestions, 
bug-reports, etc.) is more than welcome.


Kind regards,

Dimitris

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Counting various elemnts in a vactor

2013-03-26 Thread D. Rizopoulos
try this:

df - c(F, C, F, B, D, A, D, D, A, F, D, F, B, 
C)

tab - table(df)
tab
rep(names(tab), 100 * tab)


I hope it helps.

Best,
Dimitris


On 3/26/2013 9:12 AM, Katherine Gobin wrote:
 Dear R forum

 I have a vector say as given below

 df = c(F, C, F, B, D, A, D, D, A, F, D, F, B,
 C)

 I need to find

 (1) how many times each element occurs? e.g. in above vector F occurs 4 
 times, C occurs 2 times etc.

 (2) Depending on the number of occurrences, I need to repeat the element 100 
 times of the occurrences e.g. I need to repeat F 6 * 100 = 600 times, C 2*100 
 = 200 times.

 I can manage the second part i.e. repeating but I am not able to count the 
 number of times the element is appearing in a given vector.

 Kindly guide

 Katherine











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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] transpose lists

2013-03-08 Thread D. Rizopoulos
two possibilities are:

lis - list(c(12.1,0.1,12.0,1.1), c(3.44,3.00,33.10,23.00))

# 1st
m - do.call(rbind, lis)
split(m, col(m))

# 2nd
lapply(seq_along(lis[[1]]),
 function (i) sapply(lis, [, i))


I hope it helps.

Best,
Dimitris


On 3/8/2013 11:06 AM, ishi soichi wrote:
 Thanks. The result should be a list of lists like...

 x
 [[1]]
 [1] 12.10  3.44

 [[2]]
 [1] 0.1 3.0

 [[3]]
 [1] 12.0 33.1

 [[4]]
 [1]  1.1 23.0

 lapply(x, t) doesn't do the job, I think.

 ishida


 2013/3/8 PIKAL Petr petr.pi...@precheza.cz

 Hi

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of ishi soichi
 Sent: Friday, March 08, 2013 10:50 AM
 To: r-help
 Subject: [R] transpose lists

 Can you think of a function that transposes a list like

 What shall be the result of transposed list?

 Something like

 lapply(x, t)

 Regards
 Petr


 x
 [[1]]
 [1] 12.1  0.1 12.0  1.1

 [[2]]
 [1]  3.44  3.00 33.10 23.00

 ?

 ishida

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


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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] Script for conditional sums of vectors

2013-02-04 Thread D. Rizopoulos
try this:

a - c(1,1,1,1,1,1,2,2,2,2,2,2)
b - c(1,1,1,2,3,4,1,1,2,2,3,4)
c - c(400,200,300,100,500,300,200,100,500,400,200,100)
DF - data.frame(a, b, c)

with(DF, tapply(c, list(a, b), sum))


I hope it helps.

Best,
Dimitris


On 2/4/2013 10:29 AM, Benjamin Gillespie wrote:
 Hi guys,

 I hope you can help me with this (probably) simple query:

 I have a data frame:

 --

 a=c(1,1,1,1,1,1,2,2,2,2,2,2)
 b=c(1,1,1,2,3,4,1,1,2,2,3,4)
 c=c(400,200,300,100,500,300,200,100,500,400,200,100)


 data=data.frame(a=a,b=b,c=c)

 --

 And I would like to get the following output:

 --

   b
 a 1   2   3   4
 1 900 100 500 300
 2 300 900 200 100

 --

 The values in the output represent the sum of values c in data frame 
 data, for each a and b combination.

 For example, where a = 1 and b = 1, the output is 400+200+300 = 900.

 Please would anyone be able to provide a script to create my desired output?

 Many thanks in advance,
   
 Ben Gillespie
 Research Postgraduate

 School of Geography
 University of Leeds
 Leeds
 LS2 9JT


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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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 create a random matrix with conditions

2013-01-28 Thread D. Rizopoulos
You didn't say how you want these variables to be distributed, but in 
case you want a multivariate normal, then have a look at function 
mvrnorm() from package MASS, and especially at the 'empirical' argument, 
e.g.,

library(MASS)

# assumed covariance matrix
V - cbind(c(2, 1), c(1, 1.2))
V

x1 - mvrnorm(1000, c(0,0), V, empirical = FALSE)
var(x1)

x2 - mvrnorm(1000, c(0,0), V, empirical = TRUE)
var(x2)


I hope it helps.

Best,
Dimitris


On 1/28/2013 7:11 AM, Simon Givoli wrote:
 Hi!

 I want to create a random matrix with 15 variables, each variable having
 1000 observations.
 Between each two variables, I want to define a specific (*not *random)
 correlations between them, but still saving the randomness of each
 variable (mean=zero, s.d=1).
 How can I do this in R?

 thanks,
 Simon

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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] problems with coercing a factor to be numeric

2013-01-23 Thread D. Rizopoulos
Check R FAQ 7.10: How do I convert factors to numeric?


I hope it helps.

Best,
Dimitris


On 1/23/2013 10:33 AM, Francesco Sarracino wrote:
 Dear R listers,

 I am trying to compute the mean of a dummy variable that is encoded as a
 factor. However, even though the levels of my factor are 0 - 1, when I
 compute the mean (after coercing the factor to be
 numeric), R changes 0 into 1 and 1 into yes, thus altering my expected
 result.

 Please, consider the following working example:
 pp - rep(0:1, 10)
 pp - factor(pp, levels=(0:1), labels=c(no,yes))
 mean(pp) #this won't work because the argument is not numeric or logical
 mean(as.integer(pp)) # this computes the average, but not on the range 0-1,
 but 1-2. Indeed, the result is 1.5 and not 0.5 as expected.

 What am I doing wrong?
 Thanks in advance for your kind support,
 f.



-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] problems with coercing a factor to be numeric

2013-01-23 Thread D. Rizopoulos
check also

pp - rep(0:1, 10)
pp - factor(pp, levels=(0:1), labels=c(no,yes))

unclass(pp)
unclass(pp) - 1


Best,
Dimitris


On 1/23/2013 10:48 AM, Francesco Sarracino wrote:
 Dear Dimitris,

 thanks for your quick reply. I've tried the solutions proposed in 7.10
 How do I convert factors to numeric?

 as.numeric(as.character(pp))
 and
 as.numeric(levels(pp))[as.integer(pp)]

 However, whatever I do, I get Warning message: NAs introduced by coercion
 and the output is a vector of NA.

 Any ideas?
 f.



 On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl
 mailto:d.rizopou...@erasmusmc.nl wrote:

 Check R FAQ 7.10: How do I convert factors to numeric?


 I hope it helps.

 Best,
 Dimitris


 On 1/23/2013 10:33 AM, Francesco Sarracino wrote:
   Dear R listers,
  
   I am trying to compute the mean of a dummy variable that is
 encoded as a
   factor. However, even though the levels of my factor are 0 - 1,
 when I
   compute the mean (after coercing the factor to be
   numeric), R changes 0 into 1 and 1 into yes, thus altering my
 expected
   result.
  
   Please, consider the following working example:
   pp - rep(0:1, 10)
   pp - factor(pp, levels=(0:1), labels=c(no,yes))
   mean(pp) #this won't work because the argument is not numeric or
 logical
   mean(as.integer(pp)) # this computes the average, but not on the
 range 0-1,
   but 1-2. Indeed, the result is 1.5 and not 0.5 as expected.
  
   What am I doing wrong?
   Thanks in advance for your kind support,
   f.
  
  

 --
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478
 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014
 Web: http://www.erasmusmc.nl/biostatistiek/




 --
 Francesco Sarracino, Ph.D.
 https://sites.google.com/site/fsarracino/

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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 two lists, list by list

2013-01-23 Thread D. Rizopoulos
you just need:

mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE)


I hope it helps.

Best,
Dimitris


On 1/23/2013 11:01 AM, Alaios wrote:
 Thanks a lot Petr,
 for the answer
 unfortunately that would convert everything to a matrix

 num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ...

 but if you check below you can see that I Want those to form a list.

 Regards
 Alex




 
   From: PIKAL Petr petr.pi...@precheza.cz

 Sent: Tuesday, January 22, 2013 11:51 AM
 Subject: RE: [R] Concatenate two lists, list by list

 Hi

 Maybe you could use mapply

 mapply(c, Part1$dataset,Part2$dataset)

 Regards
 Petr

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Alaios
 Sent: Tuesday, January 22, 2013 11:26 AM
 To: R help
 Subject: [R] Concatenate two lists, list by list

 Dear all,
 I would like to concatenate the lists below

 str(Part2$dataset)
 List of 3
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...



 str(Part1$dataset)
 List of 3
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...


 I tried concatenating those with:


 str(cbind(Part1$datase,Part2$dataset))
 List of 6
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
   - attr(*, dim)= int [1:2] 3 2


 but I want something different. To concatenate those into  a list by
 list operation so I will end up with something looking like that

 str(concatenatedLists)

 List of 3
   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
   - attr(*, dim)= int [1:2] 3 2


 Is there anything that can do that in R?

 Regards
 Alex
  [[alternative HTML version deleted]]
   [[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.


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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 two lists, list by list

2013-01-23 Thread D. Rizopoulos
In this example, I get the following:

lis1 - replicate(3, rnorm(5), simplify = FALSE)
lis2 - replicate(3, rnorm(5), simplify = FALSE)

lis1
lis2
mapply(c, lis1, lis2, SIMPLIFY = FALSE)


Best,
Dimitris


On 1/23/2013 11:58 AM, Alaios wrote:
 Thanks a lot.
 Unfortunately that did not help either.

 num [1:32003, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
   - attr(*, dimnames)=List of 2
..$ : chr [1:32003] ...
..$ : NULL

 but I want to get

   List of 3
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, dim)= int [1:2] 3 2
  


 I am sorry that I can not find  reproducible example to show you

 Alex

 
 *From:* D. Rizopoulos d.rizopou...@erasmusmc.nl
 *To:* Alaios ala...@yahoo.com
 *Cc:* PIKAL Petr petr.pi...@precheza.cz; R help R-help@r-project.org
 *Sent:* Wednesday, January 23, 2013 11:08 AM
 *Subject:* Re: [R] Concatenate two lists, list by list

 you just need:

 mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE)


 I hope it helps.

 Best,
 Dimitris


 On 1/23/2013 11:01 AM, Alaios wrote:
   Thanks a lot Petr,
   for the answer
   unfortunately that would convert everything to a matrix
  
   num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
  
   but if you check below you can see that I Want those to form a list.
  
   Regards
   Alex
  
  
  
  
   
From: PIKAL Petr petr.pi...@precheza.cz
 mailto:petr.pi...@precheza.cz
  
   Sent: Tuesday, January 22, 2013 11:51 AM
   Subject: RE: [R] Concatenate two lists, list by list
  
   Hi
  
   Maybe you could use mapply
  
   mapply(c, Part1$dataset,Part2$dataset)
  
   Regards
   Petr
  
   -Original Message-
   From: r-help-boun...@r-project.org
 mailto:r-help-boun...@r-project.org [mailto:r-help-bounces@r-
   project.org http://project.org/] On Behalf Of Alaios
   Sent: Tuesday, January 22, 2013 11:26 AM
   To: R help
   Subject: [R] Concatenate two lists, list by list
  
   Dear all,
   I would like to concatenate the lists below
  
   str(Part2$dataset)
   List of 3
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
  
  
  
   str(Part1$dataset)
   List of 3
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
  
  
   I tried concatenating those with:
  
  
   str(cbind(Part1$datase,Part2$dataset))
   List of 6
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, dim)= int [1:2] 3 2
  
  
   but I want something different. To concatenate those into  a list by
   list operation so I will end up with something looking like that
  
   str(concatenatedLists)
  
   List of 3
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
$ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, dim)= int [1:2] 3 2
  
  
   Is there anything that can do that in R?
  
   Regards
   Alex
[[alternative HTML version deleted]]
   [[alternative HTML version deleted]]
  
  
  
   __
   R-help@r-project.org mailto: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.
  

 --
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014
 Web: http://www.erasmusmc.nl/biostatistiek/


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] Simple use of dcast (reshape2 package)

2013-01-22 Thread D. Rizopoulos
you could try the following:

DF - read.table(textConnection(
  Target Eaten ID
50  TPP 0  1
51  TPP 1  2
52  TPP 3  3
53  TPP 1  4
54  TPP 2  5
50.1GPA 9  1
51.1GPA11  2
52.1GPA 8  3
53.1GPA 8  4
54.1GPA10  5), header = TRUE)


newDF - as.data.frame(with(DF, tapply(Eaten, list(ID, Target), c)))
newDF$ID - unique(DF$ID)
newDF


I hope it helps.

Best,
Dimitris



On 1/22/2013 10:23 AM, Patrick Connolly wrote:
 Suppose I have a small dataframe

 aa
   Target Eaten ID
 50  TPP 0  1
 51  TPP 1  2
 52  TPP 3  3
 53  TPP 1  4
 54  TPP 2  5
 50.1GPA 9  1
 51.1GPA11  2
 52.1GPA 8  3
 53.1GPA 8  4
 54.1GPA10  5

 And I want to reshape it into

ID TPP GPA
 1  1   0   9
 2  2   1  11
 3  3   3   8
 4  4   1   8
 5  5   2  10

 I realise that dcast function in the reshape2 package can handle much
 more complicated tasks than that, but I can't make it do a simple one.

 If I simply tried

 dcast(aa, ... ~ Target)
 Using ID as value column: use value.var to override.
 Aggregation function missing: defaulting to length
Eaten GPA TPP
 1 0   0   1
 2 1   0   2
 3 2   0   1
 4 3   0   1
 5 8   2   0
 6 9   1   0
 710   1   0
 811   1   0

 As per the help file, it's giving counts of the numbers in the Eaten
 column since that's the default fun.aggregate value.

 My questions are: what fun.aggregate would work?  Alternatively, can
 value.var be set to something useful?

 TIA


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] apply calculations to elements in a vector

2012-11-16 Thread D. Rizopoulos
Try this:

x - c(10, 20, 30)
head(x, -1) + tail(x, -1)



I hope it helps.

Best,
Dimitris


On 11/16/2012 3:50 PM, e-letter wrote:
 Readers,

 If a vector consists of:

 10
 20
 30

 how to create a new vector based upon the results of calculations to
 the elements, e.g. addition of successive elements, so that a new
 vector would be:

 30
 50

 i.e. 10+20, then 20+30, etc.?

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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] multiply each row in a matrix with the help of the for loop

2012-11-13 Thread D. Rizopoulos
Another alternative is:

aa - array(0, dim = c(3,3,3))
a - matrix(1, 3, )

for (i in 1:3) {
  a[i, ] - -a[i, ]
  aa[, , i] - a
}

aa

I hope it helps.

Best,
Dimitris



From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of 
arun [smartpink...@yahoo.com]
Sent: Tuesday, November 13, 2012 15:25
To: Haris Rhrlp
Cc: R help
Subject: Re: [R] multiply each row in a matrix with the help of the for loop

HI,

May be this helps:
list1-lapply(lapply(1:3,function(i) {aa[1:i,,i]-a[1:i,]*-1
 return(aa[,,i])}),function(x) apply(x,2,function(i) ifelse(i==0,1,x)))
res-array(unlist(list1),dim=c(nrow(list1[[1]]),ncol(list1[[1]]),length(list1)))


 res
#, , 1
#
 #[,1] [,2] [,3]
#[1,]   -1   -1   -1
#[2,]111
#[3,]111

#, , 2
#
# [,1] [,2] [,3]
#[1,]   -1   -1   -1
#[2,]   -1   -1   -1
#[3,]111
#
#, , 3

  #   [,1] [,2] [,3]
#[1,]   -1   -1   -1
#[2,]   -1   -1   -1
#[3,]   -1   -1   -1


A.K.

- Original Message -
From: Haris Rhrlp haris_r_h...@yahoo.com
To: R-help@r-project.org R-help@r-project.org
Cc:
Sent: Tuesday, November 13, 2012 7:41 AM
Subject: [R] multiply each row in a matrix with the help of the for loop

Dear R users,

I have this program
aa-array(rep(0,27),dim=c(3,3,3))
a-matrix(rep(1,9),ncol=3)
n-0

for (i in 1:3) {

  a[i,]-a[i,]*(-1)
  n-n+1
  aa[,,n]-a[i,]

}

but i real want to multiply each row  with -1 according to for loop and after 
that to put it in the array.

I will give an example for what excaclty want

-1 -1 -1
 1  1  1
 1  1  1

-1 -1 -1
-1 -1 -1
 1  1  1

-1 -1 -1
-1 -1 -1
-1 -1 -1
[[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] Selected matrices of an array and put into a list

2012-11-12 Thread D. Rizopoulos
One approach is:

BB - rnorm(6*5*27)
dim(BB) - c(6, 5, 27)

lapply(2:27, function (i) BB[, , i])


I hope it helps.

Best,
Dimitris


On 11/12/2012 8:56 AM, Haris Rhrlp wrote:
 Dear R users,

 I have an array that has matrices that i want BB[16,5,2:27]
 i want to put each of the 26 matrices into a List

 thanks in advance
   [[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.


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] simple coversion of matrix rows to matrix columns

2012-11-07 Thread D. Rizopoulos
try this:

a - matrix(1:30, ncol= 3 )
t(a)


I hope it helps.

Best,
Dimitris



On 11/7/2012 12:50 PM, Andras Farkas wrote:
 Dear All

 I would like to convert matrix rows to columns. I am thinking the t() 
 function should help, but am having a hard time converting the matrix into 
 the dimensions I would like them to. Example:

 a -matrix(c(1:30),ncol=3) gives me:[,1] [,2] [,3]
   [1,]1   11   21
   [2,]2   12   22
   [3,]3   13   23
   [4,]4   14   24
   [5,]5   15   25
   [6,]6   16   26
   [7,]7   17   27
   [8,]8   18   28
   [9,]9   19   29
 [10,]   10   20   30

 I would like to convert the above into a matrix that looks like this with 3 
 rows and 10 columns:

 1 2   3   4   5   6   7   8   9  10
 11   12  13  14  15  16  17  18  19  20
 21   22  23  24  25  26  27  28  29  30

 I have tried :
 b -t(matrix(a))

 but I am getting a 1X30 double matrix. I also Tried to specify
 b -t(matrix(a),byrow=TRUE,ncol=10)
 but that does not help either...




 apreciate your help,



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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] averaging a list of matrices element wise

2012-11-05 Thread D. Rizopoulos
If you don't have any NAs, then one way is:

n - 3
r - 5
s - 6
raw - lapply(seq_len(n), function(i){
   matrix(rnorm(r * s), ncol = r)
})

Reduce(+, raw) / length(raw)


I hope it helps.

Best,
Dimitris


On 11/5/2012 11:32 AM, ONKELINX, Thierry wrote:
 Dear all,

 I have a list of n matrices which all have the same dimension (r x s). What 
 would be a fast/elegant way to calculate the element wise average? So 
 result[1, 1] - mean(c(raw[[1]][1, 1] , raw[[2]][1, 1], raw[[...]][1, 1], 
 raw[[n]][1, 1]))

 Here is my attempt.

 #create a dummy dataset
 n - 3
 r - 5
 s - 6
 raw - lapply(seq_len(n), function(i){
matrix(rnorm(r * s), ncol = r)
 })

 #do the calculation
 result - array(dim = c(dim(raw[[1]]), length(raw)))
 for(i in seq_along(raw)){
result[,,i] - raw[[i]]
 }
 result - apply(result, 1:2, mean)


 Best regards,

 Thierry

 ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
 Forest
 team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
 Kliniekstraat 25
 1070 Anderlecht
 Belgium
 + 32 2 525 02 51
 + 32 54 43 61 85
 thierry.onkel...@inbo.be
 www.inbo.be

 To call in the statistician after the experiment is done may be no more than 
 asking him to perform a post-mortem examination: he may be able to say what 
 the experiment died of.
 ~ Sir Ronald Aylmer Fisher

 The plural of anecdote is not data.
 ~ Roger Brinner

 The combination of some data and an aching desire for an answer does not 
 ensure that a reasonable answer can be extracted from a given body of data.
 ~ John Tukey

 * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
 en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
 is door een geldig ondertekend document.
 The views expressed in this message and any annex are purely those of the 
 writer and may not be regarded as stating an official position of INBO, as 
 long as the message is not confirmed by a duly signed document.

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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] convert list without same component length to matrix

2012-11-01 Thread D. Rizopoulos
try this:

l - list(c(1,2,3,7), c(3,4,5,6,3), c(4,2,5,7), c(2,4,6,3,2), c(3,5,7,2))

sapply(l, head, 4)


I hope it helps.

Best,
Dimitris


On 11/1/2012 9:11 AM, Al Ehan wrote:
 Hi,

 I have this lame question. I want to convert a list (each with varies in
 length) to matrix with same row length by eliminating vectors outside the
 needed range.
 For example:

 l-list(NULL)
 l[[1]]=1,2,3.7
 l[[2]]=3,4,5,6,3
 l[[3]]=4,2,5,7
 l[[4]]=2,4,6,3,2
 l[[5]]=3,5,7,2


 #so say I want to only have 4 rows and 5 column in my matrix (or
 data.frame) and eliminating the 5th index value in l[[2]] and l[[4]]
 #what is the simplest code would be? I actually have hundreds of the list
 components.

 thanks

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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
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] [R-pkgs] New Package 'JMbayes' for the Joint Modeling of Longitudinal and Survival Data under a Bayesian approach

2012-09-19 Thread D. Rizopoulos
Dear R-users,

I would like to announce the release of the new package JMbayes 
available from CRAN (http://CRAN.R-project.org/package=JMbayes). This 
package fits shared parameter models for the joint modeling of normal 
longitudinal responses and event times under a Bayesian approach using 
JAGS, WinBUGS or OpenBUGS.

The package has a single model-fitting function called 
jointModelBayes(), which accepts as main arguments a linear mixed 
effects object fit returned by function lme() of package nlme, and a Cox 
model object fit returned by function coxph() of package survival.

* jointModelBayes() allows for joint models with relative risk survival 
submodels with Weibull or B-spline approximated baseline hazard 
functions (controlled by argument 'survMod').

* In addition, argument 'param' of jointModelBayes() specifies the 
association structure between the longitudinal and survival processes; 
available options are:

   - td-value which is the classic joint model formulation used in 
Wulfsohn and Tsiatis (1997);

   - td-extra which is a user-defined, possibly time-dependent, term 
based on the specification of  the 'extraForm' argument of 
jointModelBayes(). This could be used to include terms, such as the 
time-dependent slope (i.e., the derivative of the subject-specific 
linear predictor of the linear mixed model), and the time-dependent 
cumulative effect (i.e., the integral of the subject-specific linear 
predictor of the linear mixed model);

   - td-both which is the combination of the previous two 
parameterizations, i.e., the current value and the user-specified terms 
are included in the linear predictor of the relative risk model; and

   - shared-RE where only the random effects of the linear mixed model 
are included in the linear predictor of the survival submodel.

The package also provides functionality for computing dynamic 
predictions for the longitudinal and time-to-event outcomes using 
functions predict() and survfitJM(), respectively.

As always, any kind of feedback (questions, suggestions, bug-reports, 
etc.) is more than welcome.


Best,
Dimitris

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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