test.census: Census data for hypothetical plant

Description Usage Format Examples

Description

Three years of census data for a hypothetical plant with three stage classes.

Usage

1

Format

A data frame with 41 census observations on the following variables

plant

Plant id number

year

Year of census

stage

Stage class: seedling, vegetative, or reproductive

fruits

Total number of fruits

Examples

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
data(test.census)
stages <- c("seedling", "vegetative", "reproductive")

## Cross-tabulate stage vectors and order rows by stage
sv<- table(test.census$stage, test.census$year)[stages,]
sv
stage.vector.plot(sv)

## set xaxt='n' to avoid fractions of a year (2002.5)
stage.vector.plot(sv, prop=FALSE, xaxt="n", las=1)
 axis(1, 2001:2003, c(2001, 2002, 2003))


## Convert census data to state-fate transition table using reshape
reshape(test.census, direction="wide", idvar="plant", timevar="year")

## Convert census data  to state-fate transition table using merge
trans <- subset(merge(test.census, test.census, by="plant", sort=FALSE), 
               year.x==year.y-1)
trans

## Format column and row names
trans<-trans[,c(1:4,6)]
colnames(trans)[2:5] <- c("year", "stage", "fruits", "fate")
rownames(trans) <- 1:nrow(trans)
## Order stage and fate columns
trans$stage <- ordered(trans$stage, levels = stages)
trans$fate  <- ordered(trans$fate,  levels = c(stages,"dead"))

## Select transitions for 2001-2002 and count offspring (seedlings)
trans01 <- subset(trans, year==2001)
seedlings<-nrow(subset(test.census, year==2002 & stage=="seedling"))

## Add individual fertilities using "anonymous reproduction"  based on the 
## proportional reproductive outputs of flowering plants and the total number 
## of seedlings at the end of the projection interval
trans01$seedling<-trans01$fruits/sum(trans01$fruits) * seedlings
trans01

##  Create transition frequency table  and build T matrix
tf<-table( trans01$fate, trans01$stage )
tf
## remove "dead" fate from matrix
## T.mat<-prop.table(tf,2)[-4,]
T.mat<-prop.table(tf,2)[stages,]
T.mat

## Summarize stage-specific fertility rates and build F matrix
fert<-tapply(trans01$seedling, trans01$stage, mean)
fert
F.mat<-T.mat*0
F.mat[1,]<- fert
F.mat

## The final projection matrix is just
T.mat+F.mat

## OR use projection matrix function - 
projection.matrix(trans01)

popbio documentation built on May 4, 2018, 1:04 a.m.