Re: [R] Looking for simpler solution to probabilistic question

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue, 15 Jan 2008 13:55:34 +0100

matrix(age1, ncol=length(age1), nrow=length(age2), byrow=TRUE) + age2

can be replaced by

outer(age2, age1, "+")

and the same for 'p'.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hi
>
> I have two processes which take with a certain probability (p1 and
> p2) x
> number of years to complete (age1 and age2). As soon as thge first
> process is completed, the second one begins. I want to calculate the
> time it takes for the both processes to be completed.
>
> I have the following script which gives me the answer, butI think
> there
> must be a more elegant way of doing the calculations between the
> #####
>
> Any ideas welcom,
>
> Rainer
>
>
> age1 <- 1:20
> p1 <- dnorm(age1,10,2)
>
> age2 <- 10:30
> p2 <- dnorm(age2,15,1)
>
> ######
> age <- matrix(age1, ncol=length(age1), nrow=length(age2),
> byrow=TRUE) + age2
>
> p <- matrix(p1, ncol=length(p1), nrow=length(p2), byrow=TRUE) + p2
> p <- as.numeric(tapply(p, age, sum))
> p <- p / sum(p)
> #####
>
> age <- sort(unique(as.numeric(age)))
>
> plot(age, p)
>
> lines(age1, p1)
> lines(age2, p2)
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 15 Jan 2008 - 12:58:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Jan 2008 - 13:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive