Monday, January 13, 2020
Using raster data in Netlogo
I am trying to replicate the procedure described on page 111-114 in AGIS. The generated clipped population data file cannot be read into NetLogo. After some digging, here is the problem and the solution is really simple: just add '-co force_cellsize=true' to the text box for additional command-line parameters.
Tuesday, December 31, 2019
Saturday, December 28, 2019
NetLogo
I enjoyed reading the book Agent-Based Modeling & Geographical Information Systems. I first got interested in agent-based modeling around 1999. At that time, the only software platform for this kind of modeling is Mathematica. Now with free and open source software like NetLogo, it is much easier to translate ideas into executable code and see the results.
A large number of agent-based models have been developed. OpenABM is an online repository for such models, the majority of which were developed in NetLogo.
A large number of agent-based models have been developed. OpenABM is an online repository for such models, the majority of which were developed in NetLogo.
Tuesday, December 03, 2019
Saturday, November 16, 2019
Interactive computing using C++ within the Atom editor
With the xeus-cling project, it is possible to do interactive computing using C++ inside a Jupyter notebook. With the Hydrogen project, I would think that the same can be done inside the Atom editor. I gave it a try with no luck. The problem was that while xeus-cling created a number of C++ kernels such as "C++ 11", "C++14", and "C++17", it did not create a kernel named "C++", which is what Hydrogen looks for. Follow the suggestion mentioned in this post, I was able to get rid of the error message and get the system to work. Wow!
Wednesday, November 06, 2019
Saturday, October 05, 2019
Tuesday, October 01, 2019
How to use math symbols with ggdag
The wonderful package ggdag can easily make DAG like this:
However, what we really want to include in publications is something like this:
The second one can include subscript and superscript, among many others. After some tweaking, I found a solution, not perfect but usable for now.
-----------------------------------------------------------------
library(dagitty)
library(ggdag)
library(ggraph)
library(cowplot)
library(dplyr)
```{r, echo=FALSE}
dag <- dagify(Y1 ~ X + Z1 + Z0 + U + P,
Y0 ~ Z0 + U,
X ~ Y0 + Z1 + Z0 + P,
Z1 ~ Z0,
P ~ Y0 + Z1 + Z0,
exposure = "X",
outcome = "Y1")
dag %>%
tidy_dagitty(layout = "auto", seed = 12345) %>%
arrange(name) %>%
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_point() +
geom_dag_edges() +
geom_dag_text(parse = TRUE, label = c("P", "U", "X", expression(Y[0]), expression(Y[1]), expression(Z[0]), expression(Z[1]))) +
theme_dag()
-----------------------------------------------------------------
Here the trick is to sort the tidy version of the DAG data by "name", then we can assign labels by the order of the name of the nodes. I hope a more automated approach can be developed in the future.
By the way, with the package latex2exp, it is straightforward to use LaTeX instead of plotmath commands.
However, what we really want to include in publications is something like this:
The second one can include subscript and superscript, among many others. After some tweaking, I found a solution, not perfect but usable for now.
-----------------------------------------------------------------
library(dagitty)
library(ggdag)
library(ggraph)
library(cowplot)
library(dplyr)
```{r, echo=FALSE}
dag <- dagify(Y1 ~ X + Z1 + Z0 + U + P,
Y0 ~ Z0 + U,
X ~ Y0 + Z1 + Z0 + P,
Z1 ~ Z0,
P ~ Y0 + Z1 + Z0,
exposure = "X",
outcome = "Y1")
dag %>%
tidy_dagitty(layout = "auto", seed = 12345) %>%
arrange(name) %>%
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_point() +
geom_dag_edges() +
geom_dag_text(parse = TRUE, label = c("P", "U", "X", expression(Y[0]), expression(Y[1]), expression(Z[0]), expression(Z[1]))) +
theme_dag()
-----------------------------------------------------------------
Here the trick is to sort the tidy version of the DAG data by "name", then we can assign labels by the order of the name of the nodes. I hope a more automated approach can be developed in the future.
By the way, with the package latex2exp, it is straightforward to use LaTeX instead of plotmath commands.
Friday, September 06, 2019
Subscribe to:
Posts (Atom)

