Giter Club home page Giter Club logo

Comments (3)

leifeld avatar leifeld commented on July 29, 2024

Can you post a minimal reproducible example? Thanks.

from tnam.

ThomasCNotts avatar ThomasCNotts commented on July 29, 2024

#I'm not sure about minimal but here goes...

graphoutput.txt

library(igraph)
library(tnam)

#Edit the file to be .csv and then edit this line to read it in
dat <- read.csv("PATH/graphoutput.csv", header=FALSE, sep=",")

dat <- dat[,1:110]
g <- graph_from_adjacency_matrix(data.matrix(dat), mode=c("directed"), weighted=TRUE)

g <- delete_vertex_attr(g, "name")

x <- length(degree(g))

#store one copy the network variable here: 'net1 <- as.integer...' in lab notes
net1 <- array(as.integer(as_adjacency_matrix(g, attr="weight", sparse=FALSE)), dim=c(x,x)) #Just the factories

mode(net1) <- "integer"

V(g)$diffusion=0
good <- 5 #Number of good buyers
s <- c(1:5)#list of the good buyers
V(g)$diffusion[s] <- 1

#store one copy of each covariate 'wt1 <- c(...)' in lab notes
wt <- c() #Total weight
bc <- c() #Buyer connections
sn <- c() #Connected to a seed node
sn2 <- c() #Connected to a node connected to a seed node
for (i in 1:x){
wt <- c(wt, sum(E(g)[from(i)]$weight)) #total weight out as a measure of factory size; doesn't change over time
bc <- c(bc, sum(neighbors(g,i,mode=c("out")) %in% s)) #Number of buyers a factory is connected to
if (sum(neighbors(g,i,mode=c("out")) %in% which(V(g)$diffusion == 1)) > 0){ #Is the node connected to a seed?
sn <- c(sn, 1)
}else{
sn <- c(sn, 0)
}
}

for (i in 1:x){
if (sum(neighbors(g,i,mode=c("out")) %in% which(sn==1)) > 0){
sn2 <- c(sn2, 1)
}else{
sn2 <- c(sn2, 0)
}
}

num_edge <- length(E(g))

goes <- 8
diffs <- matrix(nrow=x, ncol=goes)

for (i in 1:goes){
for (edg in sample(1:num_edge, num_edge, replace=FALSE)){
buyer <- ends(g, E(g)[edg])[,2]
seller <- ends(g, E(g)[edg])[,1]

if (V(g)$diffusion[buyer] == 1){
#in to buyer
into <- sum(E(g)[to(buyer)]$weight)
#out from neighbour =
outof <- sum(E(g)[from(seller)]$weight)

topline <- E(g)[seller %--% buyer]$weight

if (topline/outof > topline/into){V(g)$diffusion[seller] = 1}
}
}
#store one column of the diffusion dependent variable here
diffs[,i] <- V(g)$diffusion[1:x]
}

colnames(diffs) <- c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8")
rownames(diffs) <- c(1:x)
mode(diffs) <- "integer"
diffs <- as.data.frame(diffs)

tnet <- list(net1, net1, net1, net1, net1, net1, net1, net1)
names(tnet) <- c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8")
#Do the names of all variables:
for (i in 1:length(tnet)) {
rownames(tnet[[i]]) <- c(1:x)
}
names(wt) <- c(1:x)
names(bc) <- c(1:x)
names(sn) <- c(1:x)

model1 <- tnam(
diffs ~
covariate(wt, coefname = "wt") +
weightlag(diffs, tnet) +
centrality(tnet, type = "indegree") +
centrality(tnet, type = "outdegree") +
clustering(tnet, directed = TRUE) +
degreedummy(tnet, deg = 0, type = c("indegree")) +
degreedummy(tnet, deg = 0, type = c("outdegree"))
)
summary(model1)

from tnam.

leifeld avatar leifeld commented on July 29, 2024

The problem is that your wt covariate is identical with the outdegree, thereby causing an identification problem. At least for the first time point. After that, the covariate is NA, which probably doesn't help because all those other time points never enter the model because they are dropped due to the NA values. You can inspect your data structure by either running the model terms as separate functions or using tnamdata instead of tnam in your function call.

from tnam.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.