Learn R Programming

OriGen (version 1.4.3)

FitMultinomialModel: Fit OriGen allele frequency surfaces

Description

This function fits allele frequency surfaces to microsatellite data.

Usage

FitMultinomialModel(DataArray,SampleCoordinates,MaxGridLength=20,RhoParameter=10)

Arguments

DataArray
An array giving the number of alleles grouped by sample sites for each SNP. The dimension of this array is [MaxAlleles,SampleSites,NumberLoci].
SampleCoordinates
This is an array which gives the longitude and latitude of each of the found sample sites. The dimension of this array is [SampleSites,2], where the second dimension represents longitude and latitude respectively.
MaxGridLength
An integer giving the maximum number of boxes to fill the longer side of the region. Note that computation time increases quadratically as this number increases, but this number also should be high enough to separate different sample sites otherwise they
RhoParameter
This is a real precision parameter weighting the amount of smoothing. A higher value flattens out the surface while a lower value allows for more fluctuations. The default value of 10 was used in our analysis and should prove a good starting point. To

Value

  • List with the following components:
  • AlleleFrequencySurfacesAn array giving the allele frequency for each allele, each coordinate, and each SNP. The dimension of this array is [MaxAlleles, NumberLoci, NumberLongitudeDivisions, NumberLatitudeDivisions], where either NumberLongitudeDivisions or NumberLatitudeDivisions is equal to MaxGridLength(an input to this function) and the other is scaled so that the geodesic distance between points horizontally and vertically is equal.
  • DataArrayAn array giving the number alleles grouped by sample sites for each locus. The dimension of this array is [MaxAlleles,SampleSites,NumberSNPs].
  • RhoParameterA real value showing the inputted RhoParameter value.
  • SampleSitesThis shows the integer number of sample sites found.
  • GridLengthAn array giving the number of longitudinal and latitudinal divisions. The dimension of this array is [2], where the first number is longitude and the second is latitude.
  • MaxGridLengthAn integer giving the maximum number of boxes to fill the longer side of the region. Note that computation time increases quadratically as this number increases, but this number also should be high enough to separate different sample sites otherwise they will be binned together as a single site. This number was part of the inputs.
  • MaxAllelesThis shows the maximum of AllelesAtLocus. The maximum number of alleles at all loci.
  • NumberLociThis shows the integer number of loci found.
  • SampleCoordinatesThis is an array which gives the longitude and latitude of each of the found sample sites. The dimension of this array is [SampleSites,2], where the second dimension represents longitude and latitude respectively.
  • AllelesAtLocusThis shows the integer vector of alleles found at each locus.
  • GridCoordinatesAn array showing the corresponding coordinates for each longitude and latitude division. The dimension of this array is [2,MaxGridLength], with longitude coordinates coming first and latitude second. Note that one of these rows may not be filled entirely. The associated output GridLength should be used to find the lengths of the two rows. Rows not filled in entirely will contain zeroes at the end.

References

Ranola J, Novembre J, Lange K (2014) Fast Spatial Ancestry via Flexible Allele Frequency Surfaces. Bioinformatics, in press.

See Also

ConvertMicrosatData for converting Microsatellite data files into a format appropriate for analysis, ConvertPEDData for converting Plink PED files into a format appropriate for analysis,

FitOriGenModel for fitting allele surfaces to the converted SNP data,

FitMultinomialModel for fitting allele surfaces to the converted Microsatellite data,

PlotAlleleFrequencySurface for a quick way to plot the resulting allele frequency surfaces from FitOriGenModel or FitMultinomialModel,;

Examples

Run this code
#These examples are not run because they take a little more than 5 secs 
#note - type example(FunctionName, run.dontrun=TRUE) to run the example where FunctionName is
#the name of the function

##Data generation
SampleSites=10
NumberLoci=4
MaxAlleles=4
if(MaxAlleles==2){
	NumberAllelesAtEachLocus=rep(2,NumberLoci)
}else{
	NumberAllelesAtEachLocus=sample(2:MaxAlleles,NumberLoci,replace=TRUE)
}
TestData=array(0,dim=c(MaxAlleles,SampleSites,NumberLoci))
for(i in 1:NumberLoci){
	for(j in 1:NumberAllelesAtEachLocus[i]){
		TestData[j,,i]=sample(1:10,SampleSites,replace=TRUE)
	}
}
##This data is simulated in Europe which is around Longitude -9 to 38 and Latitude 34 to 60
TestCoordinates=array(0,dim=c(SampleSites,2))
TestCoordinates[,1]=runif(SampleSites,-9,38)
TestCoordinates[,2]=runif(SampleSites,34,60)

##This simulates the unknown data
NumberUnknowns=2
UnknownData=array(0,dim=c(NumberUnknowns,2,NumberLoci))
for(i in 1:NumberUnknowns){
	for(j in 1:NumberLoci){
		UnknownData[i,,j]=sample(1:NumberAllelesAtEachLocus[j],2)
	}
}

##MaxGridLength is the maximum number of boxes allowed 
##to span the region in either direction
##Note that this number was reduced to allow the example to run in less than 5 secs
##RhoParameter is a tuning constant
print("MaxGridLength is intentionally set really low for fast examples. 
	Meaningful results will most likely require a higher value.")

##Fits the allele frequency surfaces only
SurfaceTrials=FitMultinomialModel(TestData,TestCoordinates,
	MaxGridLength=20,RhoParameter=10)
str(SurfaceTrials)
##Plotting the model
PlotAlleleFrequencySurface(SurfaceTrials,LocusNumber=1,AlleleNumber=1,
	MaskWater=TRUE,Scale=FALSE)

##You can generate heatmaps of unknown individual's placements from with the allele
##surfaces using GenerateHeatMaps or use FitMultinomialModelFindUnknowns
#HeatMapTrials=GenerateHeatMaps(SurfaceTrials,UnknownData,NumberLoci=NumberLoci)
##Plotting the unknown heat map
#PlotUnknownHeatMap(HeatMapTrials,UnknownNumber=1,MaskWater=TRUE)
	
##Fitting the model and finding the unknown locations
#UnknownTrials=FitMultinomialModelFindUnknowns(TestData,TestCoordinates,
#	UnknownData,MaxGridLength=20,RhoParameter=10)
#str(UnknownTrials)
##Plotting the unknown heat map
#PlotUnknownHeatMap(UnknownTrials,UnknownNumber=1,MaskWater=TRUE)

##Fitting the admixed model
#AdmixedTrials=FitMultinomialAdmixedModelFindUnknowns(TestData,TestCoordinates,
#	UnknownData,MaxGridLength=10,RhoParameter=10)
##Plots the admixed surface disregarding fractions less than 0.01
#PlotAdmixedSurface(AdmixedTrials,UnknownNumber=1)

Run the code above in your browser using DataLab