SuperTutor

(15)

$15/per page/Negotiable

About SuperTutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Business & Finance See all
Accounting,Business & Finance,Economics,Engineering,HR Management,Math Hide all
Teaching Since: Apr 2017
Last Sign in: 327 Weeks Ago, 5 Days Ago
Questions Answered: 12843
Tutorials Posted: 12834

Education

  • MBA, Ph.D in Management
    Harvard university
    Feb-1997 - Aug-2003

Experience

  • Professor
    Strayer University
    Jan-2007 - Present

Category > Programming Posted 18 May 2017 My Price 9.00

A program to calculate Morans I

Hi please can anyone help me out on writting the pseudo code for the Morans I in calculating spatial correlation. This is what I have done so far is attached together with the python code of the morans I, but please I need help with what I have done so far and feedback. Please you can do any edit for what I have done.

 

Thank you so much

 

 

# # morans.py # # A program to calculate Morans I - index of spatial autocorrelation. # I = (n/sum of weights)* (sum (weight_xy*meandiff_x*meandiff_y)/ sum(meandiff_x^2) # where for each cell x, weight = 1 if neighbour with y (i.e. within kernel) # *Demonstrates use of 3x3 kernels on 2D numpy arrays* # # Author: Tony Moore # # Date: August 2014 # # Import numpy, as you would any other library in Python (note the definition of 'np' as an alias) import numpy as np def moran(ar): TYPE = 'A' # this means that we're going to evaluate autocorrelation of *agricultural* areas sum_weight = 0 run_tot = 0.0 # first time to work out the mean (TYPE = 1; everything else - 'W', 'U' - is 0) for i in range(ar.shape[0]): for j in range(ar.shape[1]): if ar[i,j]==TYPE: run_tot = run_tot + 1 mean = run_tot/ ar.size numerator = 0 denominator = 0 for i in range(1,ar.shape[0]-1): for j in range(1,ar.shape[1]-1): if ar[i,j]== TYPE: meandiff_x = 1 - mean else: meandiff_x = - mean # This is where the kernel comes in - in the loop it ranges from the cell before (-1) # to the cell after (+1) in both x and y, defining a 3x3 window for k in range(-1, 1): for l in range(-1,1): if k != 0 and l != 0: if ar[i+k,j+l]== TYPE: meandiff_y = 1- mean else: meandiff_y = -mean numerator = numerator + (meandiff_x*meandiff_y) denominator = denominator + (meandiff_x*meandiff_x) sum_weight = sum_weight + 1 return (ar.size/sum_weight)*(numerator/denominator)

Pseudo Code for Morans I
Import numpy Library
Define a function “moran” with an argument named “ar” for array
Define variable “Type” as “A” (evaluate autocorrelation of agricultural areas)
Assign sum weight = 0
Assign run total = 0.0
Nested for loop - loop through each array ending up with the running total
Loop iterate through the array until reach the range defined
If within array (i, j) = Type
New run total calculation is done where “run_tot = run_tot +1”
Define new variable named “mean” to calculate the total size of datasets
mean = run_tot/ar.size
Assign numerator = 0
Assign denominator = 0
Nested for Loop, define the location of i and j assign to a specific range of cell on the x-axis
Loop iterate through the array until its reach the range specified
If location within array = Type
Calculate mean difference of x-axis = “1 – mean (calculated above)”
Else if location not = Type
Display mean difference of x-axis as the negative version of the “mean”
Nested Loop look at each cell produce a kernel of 3x3
Define the location k and l assign to a specific range, “range (-1, 1)” of cell on y-axis
If feature k and l does not = to 0
Also if array i+k, j+l = Type
Calculate the mean difference of y-axis = “1 – mean (calculated above)”
Otherwise, if they do not = Type
Display mean difference of the y-axis as the negative version of the “mean”
Calculate the assigning numerator above = “numerator + (meandiff_x*meandiff_y)”
Calculate the assigning denominator above = “denominator + (meandiff_x*meandiff_y)”
Calculate the final sum weight was assigning above = “sum_weight + 1”
Return the calculation of the Moran Index, size of the array divides by sum weight times the
numerator divided by denominator
Moran Index Coefficient = (ar.size/sum_weight) * (numerator/denominator)

Attachments:

Answers

(15)
Status NEW Posted 18 May 2017 04:05 AM My Price 9.00

-----------

Attachments

file 1495080694-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)