This page provides information about the computer program SPASIBA, an R package for spatial continuous assignment from genetic data.
SPASIBA provides functions to perform the following tasks:


To run SPASIBA you need to have different things installed first: R, the R packages INLA, RandomFields and the R package SPASIBA itself.

install.packages(pkgs='SPASIBA_0.0.2.tar.gz' , repos=NULL , type='source')

You can check that SPASIBA has been installed correctly by trying to load it:


Input and output

Input data

To use SPASIBA, you need to have four data matrices under your R session:

  • A matrix of allele counts for the various reference (or training) populations. One row per population, one column per locus. Missing data not allowed.

  • A matrix with one row per population and one column per locus giving haploid population sample size. Missing data not allowed. Missingness of genotypes in the reference population is handled in this way: an individual with SNP genotype {0,1} will resut in allele counts {0,1} and haploid population size 2. An individual with SNP genotype {NA,1} will resut in allele counts {0,1} and haploid population size 1.

  • A matrix containing coordinates of reference sampling sites. One row per sampling site, two columns (xy cartesian coordinates or lon-lat). Missing data not allowed.

  • A matrix of genotypes of individuals of unknwon geographic origin. One row per indivdual, one column per locus. This should contain allele counts of an arbitrary reference allele at each SNP locus, hence 0,1, 2 or NA (missing data are allowed here).

Assuming these matrices exist somewhere as plain text files on your disk, you can read them from R with the read.table function. If you have doubt about the format of the data, you can open the various files on the SPASIBA homepage data folder. See below for an example.


The main function SPASIBA.inf return various objects stacked in a list. This includes a matrix of estimated coordinates for individuals of unknown geographic origin.

On-line documentation

Besides the present web page, users can find information about the various functions from the R on-line help,



Reading data from external files

In the example below, the data are stored on a folder on the SPASIBA homepage. It can be also a folder on your local computer or anywhere else onthe web.

## reading coordinates of reference populations
coord.ref = read.table('https://i-pri.org/special/Biostatistics/Software/Spasiba/data/coord.ref.txt')

# reading allele counts  of reference populations
geno.ref = read.table('https://i-pri.org/special/Biostatistics/Software/Spasiba/data/geno.ref.txt')
geno.ref = as.matrix(geno.ref) 

# reading haploid reference population sizes 
size.pop.ref = read.table('https://i-pri.org/special/Biostatistics/Software/Spasiba/data/size.pop.ref.txt')
size.pop.ref = as.matrix(size.pop.ref)

## reading genotypes of individuals of unknown geographic origin
geno.unknown = read.table('https://i-pri.org/special/Biostatistics/Software/Spasiba/data/geno.unknown.txt')
geno.unknown = as.matrix(geno.unknown)

## reading true coordinates of individuals  assumed here to be of unknown geographic origin
## if you have such a file you don't need the SPASIBA program!
true.coord.unknown = read.table('https://i-pri.org/special/Biostatistics/Software/Spasiba/data/true.coord.unknown.txt')

You can check that the various data matrices have been loaded properly with head function, e.g.

head(coord.ref[1:10,]) ## here inspecting 10 first lines only

Making computations

## loading the packages
## Calling SPASIBA function for inference, prediction and assignment
res <- SPASIBA.inf(geno.ref=geno.ref,
                           loc.infcov = 1:30,

The R object returned and stored in res by the code above is a list (an object consisting of several objects). The estimated coordinates of samples of unknown geographic origins is named coord.unknown.est. It can be accessed as res$coord.unknown.est and for example plotted together with sampling sites by

       legend=c('estimate','ref pops','true'),

Making maps

See post on the Molecular Ecologist for inspiration.


The model and algorithm underlying the SPASIBA program are described in

The INLA method and the SPDE-GMRF model are presented in


b i o s t a t i s t i c s @ i-pri.org