setup_wildflower_data <- function(fdat) {
  ## This takes as input the data read from the file and creates some new parts for use by ADMB.
  ## It add columns to the rawData for index stage, year, and plant.
  ## It makes a list with the data = rawData and also Nyear, Nstage, Ndata.
  
	year <- fdat$Year - min(fdat$Year) + 1
	plant <- as.integer(fdat$PlantID)
	
	fdat$Year=as.factor(fdat$Year)
	fdat$State=relevel(fdat$State, ref="F")
	fdat$State =factor(fdat$State, levels = c("F","L","M","S","D"))
	
	fdesign=model.matrix(~State+Pods, data=fdat)
	
	list(nobs=nrow(fdat), 
		 nplants=length(unique(plant)),
		 nyears=length(unique(year)), 
		 nfixed=ncol(fdesign),
		 obs=fdat$toF, 
		 fdesign=fdesign, 
		 year=year,
		 plant=plant,
		 pods=fdat$Pods
	)
}

setup_wildflower_params <- function(nfixed, nplants, nyears){
	
	list(fcoeffs=rep(0,nfixed), 
			plant_sigma_intercept=1, 
			plant_sigma_slope=1,
			year_sigma=1,
			rcoeffs_plant_intercept=rep(0.001, nplants),
			rcoeffs_plant_slope=rep(0.001, nplants),
			rcoeffs_year=rep(0.1, nyears)
		)
}			