I am trying to run a mixed effect model on soils data that were collected at two locations in a randomized complete block design (4 blocks). I am interested in the effect of location and depth (below ground surface; 10 depths) as fixed effects, with Block (nested within Location) as the random effect. I also know that Depth is spatially auto-correlated (that is soils from 0-15cm are similar to soils at 15-30cm but not less so to soils at 30-50cm). I am trying to use the lme model below, but am getting an error message:
Error in structure(res, levels = lv, names = nm, class = "factor") :
'names' attribute [70] must be the same length as the vector [0]
Data structure:
- Nitrate concentration - dependent variable
- 2 Locations
- 10 soil depth categories (autocorrelated)
- 4 Blocks (nested within location)
Link to dataset: http://www.agroecologylab.com/other-links.html
library("nlme")
InitdataKETZ <- read.csv("http://www.agroecologylab.com/uploads/2/7/2/8/27281831/initial_dp_ketz_zeron.csv")
fit <- lme(ConcNO3 ~ Location*Depth, random = ~1|Location/Block,
correlation = corAR1(form = ~Depth|Location/Block),
data = InitdataKETZ)
If it is of any help, I have been told that the proper SAS code would be:
proc mixed;
class location block DepthCat;
model ConcNO3= Location Depth Depth*Location/ddfm=kr;
random block;
repeated Depth/ subject=Location*Block type=ar(1) r;
run;