⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moransi.nlogo

📁 基于netlogo仿真平台的
💻 NLOGO
📖 第 1 页 / 共 2 页
字号:
    let N1 ( #agents * ( S1 * ( #agents * #agents - 3 * #agents + 3 ) - #agents * S2 + 3 * sigma3 * sigma3 ) )    let N2 ( K * ( S1 * ( #agents * #agents - #agents ) - 2 * #agents * S2 + 6 * ( sigma3 * sigma3 ) ) )    let D ( ( #agents - 1) * ( #agents - 2 ) * ( #agents - 3 ) * ( sigma3 * sigma3 ) )        if debug = 3 [ type "N1: " type N1 type " N2: " type N2 type " D: " type D print "" ]        set var ( ( N1 / D ) - ( N2 / D ) - ( ( 1 / ( #agents - 1) ) * ( 1 / ( #agents - 1 ) ) ) )       ]     if formulation = "ottawa-normal" [     set var (       (         ( 1 / ( ( sigma3 * sigma3 ) * ( #agents * 2 - 1 ) ) )        * ( ( #agents * #agents ) * S1 - #agents * S2 + 3 * ( sigma3 * sigma3 ) )      )      -  ( expected * expected )    )   ]    if formulation = "ottawa-random" [    let N1 (       ( #agents        * (             (#agents * #agents - 3 * #agents + 3) * S1            - #agents * S2 + 3 * ( sigma3 * sigma3)           )       ) )    let N2 (       ( S3          * (              ( #agents * #agents - #agents ) * S1             - 2 * #agents * S2 + 6 * ( sigma3 * sigma3 )            )       ) )    let D ( ( #agents - 1 ) * ( #agents - 2 ) * ( #agents - 3 ) * ( sigma3 * sigma3) )     if debug = 3 [ type "N1: " type N1 type " N2: " type N2 type " D: " type D print "" ]        set var ( ( ( N1 - N2 ) / D ) - ( expected * expected  ) )                            ; assuming a superscript typo cuch that expected should be squared and not simply doubled   ]    if debug = 3 [ type "var: " type var print "" print "" ]     ;Z     if formulation = "oregon" [ set Z ( ( moransI - expected ) / var ) ]   if formulation = "santabarbara" [ set Z ( ( moransI - expected ) / var ) ]    if formulation = "ottawa-normal" [ set Z ( ( moransI - expected ) / var ) ]    if formulation = "ottawa-random" [ set Z ( ( moransI - expected ) / sqrt var ) ]    end; wij;; takes i and j as identifiers for two turtles; calculates weighting factor between themto-report wij [ i j ]  if weighting = "inverse-distance" [    let spatial-distance 0      ask turtle i [ set spatial-distance distance turtle j ]    ifelse spatial-distance = 0      [ report 1 ]                                            ; this is flawed - adjacent and overlapping pairs recieve the same weighting      [ report ( 1 / spatial-distance ) ]    ]     if weighting = "normalized-inverse-distance" [    let spatial-distance 0      let world-diag sqrt ( world-width * world-width + world-height * world-height )        ask turtle i [ set spatial-distance distance turtle j ]    ifelse spatial-distance = 0      [ report 1 ]                                            ; this is flawed - adjacent and overlapping pairs recieve the same weighting      [ let inverse-distance world-diag / spatial-distance      report ( inverse-distance / world-diag ) ]    ]        if weighting = "simple-distance" [      let spatial-distance 0      ask turtle i [ set spatial-distance distance turtle j ]    report spatial-distance   ]   if weighting = "normalized-distance" [      let spatial-distance 0    let world-diag sqrt ( world-width * world-width + world-height * world-height )        ask turtle i [ set spatial-distance distance turtle j ]    let normalized-spatial-distance spatial-distance / world-diag    report normalized-spatial-distance       ]endto output  type "# " type "a" type " (x,y)" print ""   ask turtles [ type who type " " type a type " (" type xcor type "," type ycor type ")" print ""]    type "a avg:" type aaverage print ""  print ""  if debug = 5 [    ask turtles  [      ask turtles with [ who > [who] of myself ] [        type [who] of myself type "->" type who type " distance "  type precision distance myself 2 print ""       ]     ]  ]    print "" type "I:" type precision moransI 5   print ""  print "" type "seed:" type seed print "" type "serial#: " type serial# print ""  print "----------------------" print ""  end@#$#@#$#@GRAPHICS-WINDOW24610602387-1-134.60811100010909001ticksCC-WINDOW5512611607Command Center0MONITOR149231237276Moran's Iabs moransI3111BUTTON14129645NILgo\nNIL1TOBSERVERNILNILNILNILSLIDER1341223645#agents#agents4301511NILHORIZONTALMONITOR150285237330Expected Valueabs expected3111CHOOSER510395602440debugdebug-1 0 1 2 3 4 50MONITOR149340238385NILZ2111CHOOSER400395503440weightingweighting"inverse-distance" "normalized-inverse-distance" "simple-distance" "normalized-distance"0SWITCH246395360428fixed-seedfixed-seed11-1000INPUTBOX245434386498input-seed-653039002425342210NumberCHOOSER133109236154formulationformulation"oregon" "santabarbara" "ottawa-normal" "ottawa-random"3CHOOSER13455236100value-distributionvalue-distribution"binary" "three" "continuous"0@#$#@#$#@WHAT IS IT?-----------This demonstrates the use of Moran's I as a measure of spatial clustering in a NetLogo model. Moran's I is the most established and widely used statistic of spatial autocorrelation. The I statistic tests if subjects which are located closer together are more likely to have similar characteristics than those which are further apart.  This program is experimental! It was produced as an exploration of spatial autocorrelation testing. It is probably not robustly statistically valid. It may serve as a starting point for further development, or if you need a 'quick and dirty' test to drop into another model. See "known issues" below, and notes on validation at http://hughstimson.org/projects/moransi.HOW IT WORKS------------Random patterns of agents are generated, each of which is randomly assigned a value. Moran's I statistic is calculated for the resulting distribution, as well as the expected value of Moran's I and a test of the significance of the I statistic given the particular layout of the agents.HOW TO USE IT-------------#agents: Controls the number of agents which are produced for a given run.value-distribution: Moran's I measures not just location of an subject, but also a value associated with that subject. In this program, each agent is randomly assigned a value. Those values can be either binary (0 or 1), one of three (0, 0.5, 1) or continuous between 0 and 1. The agents are coloured depending on their values; white for 0, black for 1, and shades of grey for intermediary values. Patterns tend to be more obvious to the observer when value-distribution is set to binary. This is equivalent to a case where agents have categorical differences (cat or dog, for instance). Continuous values are also common in modeling, and using this setting demonstrates that application.formulation:Although the formula of Moran's I is standard, there are several variations on the method used to calculate the significance of any given I value. These variations account for different assumptions about distribution and measurement of the values, and are particularly related to the measurement of variance in the values. Several of these approaches can be optionally used in this program. Each variation is named for the institution whose website I found the formulation on. Copies of the original formulas, notes on validation of the methods and links to the source pages can be found at http://hughstimson.org/projects/moransi"oregon" is the original first version that was implemented."santabarbara" is a second version with some substantial differences."ottawa-random" shares characteristics of both of the above, and appears to be the most robust. It's based on the assumption of a purely random distribution of values among the agents. This fits the expected behaviour of the random value generator."ottawa-normal" uses a very different characterization of variance, based on the assumption of a normally distributed set of values among the agents. It also returns apparently reasonable results.fixed-seedA particular model run can be reproduced by copying the random seed which NetLogo used to produce that run into the 搃nput-seed

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -