# Calculate and Rectify Moran's I

Provides a scaling method to obtain a standardized Moran's I measure. Moran's I is a measure for the spatial autocorrelation of a data set, it gives a measure of similarity between data and its surrounding. The range of this value must be [-1,1], but this does not happen in practice. This package scale the Moran's I value and map it into the theoretical range of [-1,1]. Once the Moran's I value is rescaled, it facilitates the comparison between projects, for instance, a researcher can calculate Moran's I in a city in China, with a sample size of n1 and area of interest a1. Another researcher runs a similar experiment in a city in Mexico with different sample size, n2, and an area of interest a2. Due to the differences between the conditions, it is not possible to compare Moran's I in a straightforward way. In this version of the package, the spatial autocorrelation Moran's I is calculated as proposed in Chen(2013) .

Many Geographical Analysis utilizes spatial autocorrelation, that allows us to study the geographical evolution from different points of view. One measurement for spatial autocorrelation is Moran's I, that is based on Pearson’s correlation coefficient in general statistics arXiv:1606.03658 This package offers a straight fordward to perform the whole analisys by using the function `rescaleI` which requires an input file with a specific format you can see it at [Loading data] section

## Analysis Step by Step

The analysis can be done following the steps

The input file^[The data used in this example is taken from [@chen2009].] should have the following format.

• The first column represents an unique id for the record.
• The second and third column represent the latitute and longitud of where the sample was taken
• The fourth and beyond represents the different measured variables

To load data to performe the analysis is quite simple. The function `loadFile` provides the interface to make it. loadFile returns a list with two variables, `data` and `varOfInterest`, the first one represents a vector with latitude and longitude; `varOfInterest` is a matrix with all the measurements from the field.

If the data has a chessboard shape,the file is organized in rows and columns, where the rows represent latitute and columns longitude, the measurements are in the cell. The function `loadChessBoard` can be used to load into the analysis.

### Calculate Distance

Once the data is loaded, The distance matrix, the distance between all the points might be calcualted. The distance can be calculated using `calculateEuclideanDistance' if the points are taken in a geospatial location.

If the data is taken from a chessboard a like field, the Manhattan distance can be used.

### Calculate Weighted Distance Matrix

The weighted distance matrix can be calculated it using the function `calculateWeightedDistMatrix`, however it is not required to do it, because 'calculateMoranI' does it.

### Moran's I

It is time to calculate the spatial autocorrelation statistic Morans' I. The function `calcualteMoranI`, which requires the distance matrix, and the variable you want are interested on.

### Resampling Method for I

The scaling process is made using Monte Carlo resampling method. The idea is to shuffle the values and recalculate I for at least 1000 times. In the code below, after resampling the value of I, a set of statistics are calculated for that generated vector.

#### Plotting Distribution (Optional)

To see how the value of I is distribuited, the method `plotHistogramOverlayNormal` provides the functionality to get a histogram of the vector generated by resampling with a theorical normal distribution overlay.

### Rescaling I

Once we have calculated the null distribution via resampling, you need to scale by centering and streching. The method `iCorrection`, return an object with the resampling vector rescaled, and all the summary for this vector, the new value of I is returned in a variable named `newI`

## Calculate P-value

In order to provide a significance to this new value, you can calculate the pvalue using the method `calculatePvalue`. This method requires the scaled vector, you get this vector,`scaledData`, the scaled I, `newI` and the mean of the `scaledData`.

## Stability Analysis

In order to determine how many iterations it is necessary to run the resampling method, it is possible to run a stability analysis. This function draw a chart in log scale (10^x) of the number of interations needed to achieve the stability in the Monte Carlo simulation.

# Reference manual

install.packages("Irescale")

2.3.0 by Ivan Fuentes, a year ago

https://github.tamu.edu/jivfur/rectifiedI

Browse source code at https://github.com/cran/Irescale

Authors: Ivan Fuentes , Thomas DeWitt , Thomas Ioerger , Michael Bishop

Documentation:   PDF Manual