Mixed effects model for power analysis to aid study design I am planning a study and would like to perform a power analysis to design the optimal sampling strategy. I would like to know how samples would be necessary to detect a significant effect.
The study is to assess whether there is a significant effect of habitat type on the growth rate of a species of snake. We will be collecting and measuring the length of snakes from three habitats (riverine, woodland, grassland). We expect that a snakes age will be the strongest predictor of its length. We have a way to estimate snake age to include this information in the model.
Data collected will look something like this:
Sample  length(cm)  Age(years)  Habitat
Snake1  30 3 Riverine
Snake2  43 5 Riverine
Snake3  10 1 Woodland  
Snake4  15  2 grassland

So to model if we will have power to detect an effect of habitat on the growth rate I believe I want to do a generalized mixed effect model. I want to see the effect of a categorical variable (habitat) on growth rate. I am unsure about the correct way to model this as I am only measuring snake length but it is growth rate that I am actually trying to learn, which is the slope of age and length. 
I am not very familiar with generalized mixed models. From what I have been reading would it be appropriate to run two mixed models, one with and one without habitat as a predictor variable and then use an ANOVA to compare the two models to see if habitat has a significant effect on the response variable? I do not want the model to assume that growth rate is linear in each habitat, as the growth curve is something that may vary between habitats that we are also interested to measure.  This is how I have it formulated so far but as I do not yet fully understand the model I suspect this is not correct:
Model 1: 
Length ~ (1 + age | habitat) + age
Model 2:
Length ~ (1 | habitat) + age
Then ANOVA(Model 1, Model 2)
I would greatly appreciate any assistance with formulating an appropriate model for answering this question. Once I have a model I presume I can play around with generating simulated input data with different assumptions about the effect of habitat on growth rate and then change the sample sizes to see how many snakes I would need to measure to achieve a significant result. 
It would be great to know if we assume a difference in growth rate of approximately 1cm per year how many snakes we would need to measure to detect this. 
Answers that use R are welcome though I would be most interested in conceptually understanding how to formulate the correct model to address this question. Thank you in advance for your assistance. 
 A: Mixed-effects models may be explained in multiple ways. In your example, you could think of them as a way of accounting for variance explainable by some categorical variable (such as habitat) without paying the parameter penalty of including the variable as a fixed effect. 
Suppose you had 20 different habitat types. You would have 19 implicit parameters in a regular modelling framework, while in a mixed-effects model you would be accounting for a single variance term (i.e. you would assume that the means of all 20 habitats are drawn from some normal distribution). 
Now to get to the specifics of your case: since you have only 3 habitats, you don't really pay much of a penalty (2 parameters!). And 3 units is a very small number for estimating a variance term in any case. So I actually suggest that you abandon the mixed-effects modelling framework here and include 'habitat' as a fixed effect. This leaves you with a simple linear model:
Length ~ Age * Habitat
A strong interaction term would be clear evidence for your biological hypothesis of growth rate being influenced by habitat, I think. And if you know how to do a regular power analysis, you can go ahead and do this instead of worrying about the complexities of power analysis in mixed models (for which there are methods, e.g. http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12504/full). 
Let me know if this addresses your question; I will try to clarify anything above that isn't clear, or point you towards additional resources. 
EDIT in reply to your comment: 
Answering your questions in reverse order
1) The simple linear model example I gave above will allow for different slopes in different habitats. That's what the interaction term essentially is. If you leave out an interaction term, you will force all slopes to be the same.
2) If you expand beyond 4-5 groups AND you do not care about making statistical comparisons between pairs of groups (which is probably not worth it), then you should almost certainly switch to a mixed modelling framework. In which case, the model you need would be your model 1 above, i.e. 
Length ~ Age + (1 + Age | Habitat)
Statistically testing whether your random slope term is significant is trickier, but I believe the RLRsim package lets you do this (I have not tried it, but the authors know their stuff). The simR package I linked to above will let you do the mixed model power analyses relatively easily. 
