An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130218/e8463aa4/attachment.pl>
help with population matrix
4 messages · Sam Fowler, John Kane, Roy Mendelssohn - NOAA Federal +1 more
Currently your code does not seem to make any sense ===comments in line==== John Kane Kingston ON Canada
-----Original Message-----
From: sf62 at st-andrews.ac.uk
Sent: Mon, 18 Feb 2013 16:09:49 +0000
To: r-help at r-project.org
Subject: [R] help with population matrix
Hi guys, I am a biologist and an R newbie, and I'm learning how to create
a
simple population model.
So, I have a population matrix ("pop")of 30 age classes of female (1:4
are
non-breeders, 5:30 are breeders) which will be modelled for 100 years.
pop <- matrix(0,30,100)
I then populate this matrix with 3 young adult females.
pop[5, 1] <- 3
What is this expected to do?
I then want to run this for 100 years, with stochasticity, to see how this population does over time.
for (y in 1:100) {
pop[1,t+1] <- rbinom(1,colSums(pop[5:30, t]), b/2)
(I haven't filled these in but you don't need them, they all have different survival probabilities to the sexually-mature adults.)
pop[5, t+1] <- rbinom(1, pop[4, t], s2) pop[6, t+1] <- rbinom(1, pop[5, t], s2)
.....
pop[30, t+1] <- rbinom(1, pop[29, t], s2)
}
What is t , s2 b etc?
So my question is: is there any way of populating this matrix without having to explicitly write 30 lines of code? Because lines 5 - 30 are all going to be the same, and yet even after 5 hours (literally) of web searching and R manual reading I can't find a way to index the rows, which seems to be what's needed here. Any insight is welcome here, including a different way of modelling this population. Many thanks, Sam.
This may be one of the cases where it really is better to have some detailed explanation of what you want rather than how to code it. ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
See if this helps at all: http://cran.r-project.org/web/packages/popbio/popbio.pdf -Roy M.
On Feb 18, 2013, at 8:49 AM, John Kane <jrkrideau at inbox.com> wrote:
Currently your code does not seem to make any sense ===comments in line==== John Kane Kingston ON Canada
-----Original Message-----
From: sf62 at st-andrews.ac.uk
Sent: Mon, 18 Feb 2013 16:09:49 +0000
To: r-help at r-project.org
Subject: [R] help with population matrix
Hi guys, I am a biologist and an R newbie, and I'm learning how to create
a
simple population model.
So, I have a population matrix ("pop")of 30 age classes of female (1:4
are
non-breeders, 5:30 are breeders) which will be modelled for 100 years.
pop <- matrix(0,30,100)
I then populate this matrix with 3 young adult females.
pop[5, 1] <- 3
What is this expected to do?
I then want to run this for 100 years, with stochasticity, to see how this population does over time.
for (y in 1:100) {
pop[1,t+1] <- rbinom(1,colSums(pop[5:30, t]), b/2)
(I haven't filled these in but you don't need them, they all have different survival probabilities to the sexually-mature adults.)
pop[5, t+1] <- rbinom(1, pop[4, t], s2) pop[6, t+1] <- rbinom(1, pop[5, t], s2)
.....
pop[30, t+1] <- rbinom(1, pop[29, t], s2)
}
What is t , s2 b etc?
So my question is: is there any way of populating this matrix without having to explicitly write 30 lines of code? Because lines 5 - 30 are all going to be the same, and yet even after 5 hours (literally) of web searching and R manual reading I can't find a way to index the rows, which seems to be what's needed here. Any insight is welcome here, including a different way of modelling this population. Many thanks, Sam.
This may be one of the cases where it really is better to have some detailed explanation of what you want rather than how to code it.
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! ______________________________________________ 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.
********************** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ********************** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center 1352 Lighthouse Avenue Pacific Grove, CA 93950-2097 e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address) voice: (831)-648-9029 fax: (831)-648-8440 www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill." "From those who have been given much, much will be expected" "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
It will be better if you can give us a complete example of what you want to do. You start off with a typo in your for() command using "y" but then switching to "t" in the code. You also say the rows "all have different survival probabilities" but it is not clear where that fits into the picture (b/2, s2?). Your provided code will fail when the loop reaches t=100 because you will be referencing a column beyond the size of your matrix (i.e. pop[1, 101]). Give us a reduced version of what you want to do, say 5 age categories (2 non-breeding, 3 breeding) and 5 years. It is likely that the looping can be reduced and the number of lines of code reduced, but you've left out too much for us to give you reasonable suggestions. Give us complete code for this toy version of what you are trying to do and it will be easier to see how to modify it for the bigger version. ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of John Kane Sent: Monday, February 18, 2013 10:50 AM To: Sam Fowler; r-help at r-project.org Subject: Re: [R] help with population matrix Currently your code does not seem to make any sense ===comments in line==== John Kane Kingston ON Canada
-----Original Message----- From: sf62 at st-andrews.ac.uk Sent: Mon, 18 Feb 2013 16:09:49 +0000 To: r-help at r-project.org Subject: [R] help with population matrix Hi guys, I am a biologist and an R newbie, and I'm learning how to
create
a
simple population model.
So, I have a population matrix ("pop")of 30 age classes of female
(1:4
are non-breeders, 5:30 are breeders) which will be modelled for 100
years.
pop <- matrix(0,30,100)
I then populate this matrix with 3 young adult females.
pop[5, 1] <- 3
What is this expected to do?
I then want to run this for 100 years, with stochasticity, to see how this population does over time.
for (y in 1:100) {
pop[1,t+1] <- rbinom(1,colSums(pop[5:30, t]), b/2)
(I haven't filled these in but you don't need them, they all have different survival probabilities to the sexually-mature adults.)
pop[5, t+1] <- rbinom(1, pop[4, t], s2) pop[6, t+1] <- rbinom(1, pop[5, t], s2)
.....
pop[30, t+1] <- rbinom(1, pop[29, t], s2)
}
What is t , s2 b etc?
So my question is: is there any way of populating this matrix without having to explicitly write 30 lines of code? Because lines 5 - 30 are
all
going to be the same, and yet even after 5 hours (literally) of web searching and R manual reading I can't find a way to index the rows, which seems to be what's needed here. Any insight is welcome here, including a different way of modelling
this
population. Many thanks, Sam.
This may be one of the cases where it really is better to have some detailed explanation of what you want rather than how to code it.
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! ______________________________________________ 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.