If I use the lme function in the package nlme and write
m <- lme(y ~ Time, random = ~1|Subject)
and then write
Variogram(m, form = ~Time|Subject)
it produces the variogram no problem.
However, if I use lm without the random effect,
m <- lm(y ~ Time)
and write
Variogram(m, form = ~Time)
it produces
Error in Variogram.default(m, form = ~Time) :
argument "distance" is missing, with no default
What's going on? Why does it need a distance when I fit a lm, when it didn't need it before with lme?
How then does one plot a Variogram without needing to specify "Distance"? I have the same problem using other modelling methods: glm, gam, gamm, etc.
EDIT:
You can verify all of this yourself using e.g. the BodyWeight data in nlme.
> m <- lm(weight ~ Time, data = BodyWeight)
> Variogram(m, form =~Time)
Error in Variogram.default(m, form = ~Time) :
argument "distance" is missing, with no default
In
nlme
there is aVariogram.lme
method function for anlme
fit, but there is not an equivalent method forlm
models.You can use
Variogram.default
as follows:We can also plot the variogram: