famuvie / breedR

Statistical methods for forest genetic resources analysts
http://famuvie.github.io/breedR/
GNU General Public License v3.0
31 stars 24 forks source link

Variogram scale #25

Closed famuvie closed 9 years ago

famuvie commented 9 years ago

VS requests to have some degree of control over the scale of the variogram. Useful, for example, to compare the variograms from two different models under the same scale.

famuvie commented 9 years ago

Since the users can extract the raw values to build the variograms, I'd rather let further visualizations to them. Here is an example:


## Example: fit two models to the globulus dataset
data(globulus)
gen.globulus <- list(model    = 'add_animal', 
                     pedigree = globulus[,1:3],
                     id       = 'self')
res.blk <- remlf90(fixed  = phe_X ~ gg,
                   genetic = gen.globulus, 
                   spatial = list(model = 'blocks', 
                                  coord = globulus[, c('x','y')],
                                  id = 'bl'),
                   data = globulus)
res.ar  <- remlf90(fixed  = phe_X ~ gg,
                   genetic = gen.globulus, 
                   spatial = list(model = 'AR', 
                                  coord = globulus[, c('x','y')],
                                  rho = c(.85, .8)), 
                   data = globulus)

## Get the corresponding variograms of residuals
vb <- variogram(res.blk)
va <- variogram(res.ar)

## Extract both isotropic variograms to be compared
iv <- rbind(cbind(model = 'blocks', vb[['isotropic']]),
            cbind(model = 'AR1xAR1',va[['isotropic']]))

## Then, you can plot them together under the same scale
ggplot(iv, aes(distance, variogram)) +
  geom_point() +
  geom_line() +
  stat_smooth(se = FALSE, method = 'auto') + 
  facet_wrap(~ model)