#RSiena
#start with clean workspace
rm(list=ls())
#load dataobjects
load("./data/descriptives/UU_net_array_sym.RData")
load("./data/descriptives/UUpub_dfv2.RData")
load("./data/descriptives/UU_dfv2.RData")
load("./data/soc_staff_cit.RData")
load("./data/names_staff_cit_v20221006.RData")
library(RSiena)
library(tidyverse)
names_staff_cit %>%
filter(gs_id %in% soc_df$gs_id) -> UU_staff_cit
save(UU_staff_cit, file="./data/descriptives/UU_staff_cit.RData")
#dependent
net <- sienaDependent(net_soc_array)
### Step 1: define data
#diversiteit egonet
div_net <- coCovar(as.numeric(soc_df$div.net))
#diversiteit ego
div_ego <- coCovar(as.numeric(soc_df$div.ego))
#gender
gender <- coCovar(soc_df$gender4)
#leeftijd
pub_first <- coCovar(soc_df$pub_first)
#total cites
soc_df$total_cites_num <- as.numeric(soc_df$total_cites)
total_cites <- coCovar(soc_df$total_cites_num)
#pubs: time-varying
pubsw1 <- pubsw2 <- pubsw3 <- pubsw4 <- NA
for (i in 1:length(soc_df$gs_id)) {
pubsw1[i] <- nrow(UU_staff_cit[(UU_staff_cit$gs_id == soc_df$gs_id[i]) & UU_staff_cit$year>=2016 & UU_staff_cit$year<=2017,])
pubsw2[i] <- nrow(UU_staff_cit[(UU_staff_cit$gs_id == soc_df$gs_id[i]) & UU_staff_cit$year>=2018 & UU_staff_cit$year<=2019,])
pubsw3[i] <- nrow(UU_staff_cit[(UU_staff_cit$gs_id == soc_df$gs_id[i]) & UU_staff_cit$year>=2020 & UU_staff_cit$year<=2022,])
}
pub_df <- as.matrix(data.frame(pubsw1, pubsw2, pubsw3))
pubs <- varCovar(pub_df)
mydata1 <- sienaDataCreate(net, div_net)
### Step 2: create effects structure
myeff1 <- getEffects(mydata1)
#effectsDocumentation(myeff2)
### Step 3: get initial description
print01Report(mydata1, modelname = "./data/results/UU_init1")
### Step4: specify model
myeff1 <- includeEffects(myeff1, absDiffX,interaction1="div_net")
## effectName include fix test initialValue parm
## 1 div_net abs. difference TRUE FALSE FALSE 0 0
### Step5 estimate
myAlgorithm <- sienaAlgorithmCreate(projname = "UU_init1")
## If you use this algorithm object, siena07 will create/use an output file UU_init1.txt .
(ans1 <- siena07(myAlgorithm, data = mydata1, effects = myeff1))
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.4223 ( 0.1644 )
## 0.2 Rate parameter period 2 1.0347 ( 0.3302 )
##
## Other parameters:
## 1. eval degree (density) -1.3275 ( 0.4102 ) 0.0524
## 2. eval div_net abs. difference -0.0297 ( 0.0138 ) 0.0615
##
## Overall maximum convergence ratio: 0.0636
##
##
## Total of 2028 iteration steps.
# (the outer parentheses lead to printing the obtained result on the screen) if necessary, estimate
# further
#(ans <- siena07(myAlgorithm, data = mydata, effects = myeff, prevAns = ans))
summary(ans1)
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.4223 ( 0.1644 )
## 0.2 Rate parameter period 2 1.0347 ( 0.3302 )
##
## Other parameters:
## 1. eval degree (density) -1.3275 ( 0.4102 ) 0.0524
## 2. eval div_net abs. difference -0.0297 ( 0.0138 ) 0.0615
##
## Overall maximum convergence ratio: 0.0636
##
##
## Total of 2028 iteration steps.
##
## Covariance matrix of estimates (correlations below diagonal)
##
## 0.168 -0.003
## -0.558 0.000
##
## Derivative matrix of expected statistics X by parameters:
##
## 10.984 400.939
## 184.518 18296.141
##
## Covariance matrix of X (correlations below diagonal):
##
## 13.976 514.933
## 0.654 44385.088
mydata2 <- sienaDataCreate(net, div_net)
### Step 2: create effects structure
myeff2 <- getEffects(mydata2)
#effectsDocumentation(myeff2)
### Step 3: get initial description
print01Report(mydata2, modelname = "./data/results/UU_init2")
### Step4: specify model
myeff2 <- includeEffects(myeff2, degPlus) #popularity
## effectName include fix test initialValue parm
## 1 degree act+pop TRUE FALSE FALSE 0 1
myeff2 <- includeEffects(myeff2, transTriads) #number of transitive patterns in i's relationships
## effectName include fix test initialValue parm
## 1 transitive triads TRUE FALSE FALSE 0 0
myeff2 <- includeEffects(myeff2, absDiffX,interaction1="div_net")
## effectName include fix test initialValue parm
## 1 div_net abs. difference TRUE FALSE FALSE 0 0
### Step5 estimate
myAlgorithm <- sienaAlgorithmCreate(projname = "UU_init2")
## If you use this algorithm object, siena07 will create/use an output file UU_init2.txt .
(ans2 <- siena07(myAlgorithm, data = mydata2, effects = myeff2))
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.5206 ( 0.2079 )
## 0.2 Rate parameter period 2 1.3095 ( 0.4961 )
##
## Other parameters:
## 1. eval degree (density) -2.5787 ( 0.8291 ) 0.0412
## 2. eval transitive triads 1.6350 ( 0.7979 ) 0.0372
## 3. eval degree act+pop 0.1636 ( 0.1281 ) 0.0231
## 4. eval div_net abs. difference -0.0270 ( 0.0137 ) 0.0054
##
## Overall maximum convergence ratio: 0.0896
##
##
## Total of 2003 iteration steps.
# (the outer parentheses lead to printing the obtained result on the screen) if necessary, estimate
# further
#(ans <- siena07(myAlgorithm, data = mydata, effects = myeff, prevAns = ans))
summary(ans2)
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.5206 ( 0.2079 )
## 0.2 Rate parameter period 2 1.3095 ( 0.4961 )
##
## Other parameters:
## 1. eval degree (density) -2.5787 ( 0.8291 ) 0.0412
## 2. eval transitive triads 1.6350 ( 0.7979 ) 0.0372
## 3. eval degree act+pop 0.1636 ( 0.1281 ) 0.0231
## 4. eval div_net abs. difference -0.0270 ( 0.0137 ) 0.0054
##
## Overall maximum convergence ratio: 0.0896
##
##
## Total of 2003 iteration steps.
##
## Covariance matrix of estimates (correlations below diagonal)
##
## 0.687 0.047 -0.091 -0.004
## 0.072 0.637 -0.035 -0.001
## -0.861 -0.342 0.016 0.000
## -0.314 -0.053 0.067 0.000
##
## Derivative matrix of expected statistics X by parameters:
##
## 15.583 5.181 254.584 534.655
## 4.979 4.810 113.869 159.992
## 98.436 43.257 1923.663 3204.643
## 257.095 72.194 3920.624 20382.787
##
## Covariance matrix of X (correlations below diagonal):
##
## 22.608 9.011 394.282 777.675
## 0.619 9.376 229.255 245.892
## 0.902 0.815 8444.013 12369.349
## 0.719 0.353 0.592 51779.331
mydata3 <- sienaDataCreate(net, div_net, div_ego)
### Step 2: create effects structure
myeff3 <- getEffects(mydata3)
#effectsDocumentation(myeff3)
### Step 3: get initial description
print01Report(mydata3, modelname = "./data/results/UU_init3")
### Step4: specify model
myeff3 <- includeEffects(myeff3, degPlus) #popularity
## effectName include fix test initialValue parm
## 1 degree act+pop TRUE FALSE FALSE 0 1
myeff3 <- includeEffects(myeff3, transTriads) #number of transitive patterns in i's relationships
## effectName include fix test initialValue parm
## 1 transitive triads TRUE FALSE FALSE 0 0
myeff3 <- includeEffects(myeff3, absDiffX,interaction1="div_net")
## effectName include fix test initialValue parm
## 1 div_net abs. difference TRUE FALSE FALSE 0 0
myeff3 <- includeEffects(myeff3, sameX,interaction1="div_ego")
## effectName include fix test initialValue parm
## 1 same div_ego TRUE FALSE FALSE 0 0
### Step5 estimate
myAlgorithm <- sienaAlgorithmCreate(projname = "UU_init3")
## If you use this algorithm object, siena07 will create/use an output file UU_init3.txt .
(ans3 <- siena07(myAlgorithm, data = mydata3, effects = myeff3))
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.5151 ( 0.2024 )
## 0.2 Rate parameter period 2 1.2970 ( 0.4799 )
##
## Other parameters:
## 1. eval degree (density) -2.8112 ( 0.9382 ) 0.0234
## 2. eval transitive triads 1.5653 ( 0.8515 ) 0.0093
## 3. eval degree act+pop 0.1640 ( 0.1414 ) 0.0279
## 4. eval div_net abs. difference -0.0250 ( 0.0141 ) 0.0108
## 5. eval same div_ego 0.2767 ( 0.4894 ) 0.0365
##
## Overall maximum convergence ratio: 0.0497
##
##
## Total of 2353 iteration steps.
# (the outer parentheses lead to printing the obtained result on the screen) if necessary, estimate
# further
#(ans <- siena07(myAlgorithm, data = mydata, effects = myeff, prevAns = ans))
mydata4 <- sienaDataCreate(net, div_net, div_ego, gender, pub_first, pubs, total_cites)
### Step 2: create effects structure
myeff4 <- getEffects(mydata4)
#effectsDocumentation(myeff3)
### Step 3: get initial description
print01Report(mydata4, modelname = "./data/results/UU_init4")
### Step4: specify model
myeff4 <- includeEffects(myeff4, degPlus) #popularity
## effectName include fix test initialValue parm
## 1 degree act+pop TRUE FALSE FALSE 0 1
myeff4 <- includeEffects(myeff4, transTriads) #number of transitive patterns in i's relationships
## effectName include fix test initialValue parm
## 1 transitive triads TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, absDiffX,interaction1="div_net")
## effectName include fix test initialValue parm
## 1 div_net abs. difference TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, sameX,interaction1="div_ego")
## effectName include fix test initialValue parm
## 1 same div_ego TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, sameX,interaction1="gender")
## effectName include fix test initialValue parm
## 1 same gender TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, egoPlusAltX,interaction1="pub_first") #if you are older, you will get more collaboration within department
## effectName include fix test initialValue parm
## 1 pub_first ego and alt TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, egoPlusAltX,interaction1="total_cites") #if you are older, you will get more collaboration within department
## effectName include fix test initialValue parm
## 1 total_cites ego and alt TRUE FALSE FALSE 0 0
myeff4 <- includeEffects(myeff4, egoPlusAltX, interaction1 = "pubs") #if you have many pubs, you will probably publish more per year?
## effectName include fix test initialValue parm
## 1 pubs ego and alt TRUE FALSE FALSE 0 0
### Step5 estimate
myAlgorithm <- sienaAlgorithmCreate(projname = "UU_init4")
## If you use this algorithm object, siena07 will create/use an output file UU_init4.txt .
(ans4 <- siena07(myAlgorithm, data = mydata4, effects = myeff4))
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.5919 ( 0.2477 )
## 0.2 Rate parameter period 2 1.3016 ( 0.4480 )
##
## Other parameters:
## 1. eval degree (density) -3.1638 ( 0.9011 ) -0.1348
## 2. eval transitive triads 1.6301 ( 0.8368 ) -0.1402
## 3. eval degree act+pop 0.1360 ( 0.1417 ) -0.1374
## 4. eval div_net abs. difference -0.0242 ( 0.0133 ) -0.1033
## 5. eval same div_ego 0.2191 ( 0.4741 ) -0.1412
## 6. eval same gender 0.2422 ( 0.4302 ) -0.0666
## 7. eval pub_first ego and alt 0.0179 ( 0.0199 ) 0.1355
## 8. eval total_cites ego and alt 0.0000 ( 0.0000 ) -0.1445
## 9. eval pubs ego and alt 0.8094 ( 0.4273 ) -0.1171
##
## Overall maximum convergence ratio: 0.1827
##
##
## Total of 2641 iteration steps.
# (the outer parentheses lead to printing the obtained result on the screen) if necessary, estimate
# further
#(ans <- siena07(myAlgorithm, data = mydata, effects = myeff, prevAns = ans))
summary(ans4)
## Estimates, standard errors and convergence t-ratios
##
## Estimate Standard Convergence
## Error t-ratio
##
## Rate parameters:
## 0.1 Rate parameter period 1 0.5919 ( 0.2477 )
## 0.2 Rate parameter period 2 1.3016 ( 0.4480 )
##
## Other parameters:
## 1. eval degree (density) -3.1638 ( 0.9011 ) -0.1348
## 2. eval transitive triads 1.6301 ( 0.8368 ) -0.1402
## 3. eval degree act+pop 0.1360 ( 0.1417 ) -0.1374
## 4. eval div_net abs. difference -0.0242 ( 0.0133 ) -0.1033
## 5. eval same div_ego 0.2191 ( 0.4741 ) -0.1412
## 6. eval same gender 0.2422 ( 0.4302 ) -0.0666
## 7. eval pub_first ego and alt 0.0179 ( 0.0199 ) 0.1355
## 8. eval total_cites ego and alt 0.0000 ( 0.0000 ) -0.1445
## 9. eval pubs ego and alt 0.8094 ( 0.4273 ) -0.1171
##
## Overall maximum convergence ratio: 0.1827
##
##
## Total of 2641 iteration steps.
##
## Covariance matrix of estimates (correlations below diagonal)
##
## 0.812 0.130 -0.090 -0.003 -0.157 -0.121 -0.005 0.000 -0.081
## 0.172 0.700 -0.038 -0.001 -0.048 0.005 0.002 0.000 -0.014
## -0.704 -0.324 0.020 0.000 0.000 0.003 0.001 0.000 -0.007
## -0.264 -0.051 -0.050 0.000 0.001 0.000 0.000 0.000 0.000
## -0.369 -0.122 -0.003 0.122 0.225 -0.008 0.000 0.000 0.003
## -0.311 0.014 0.055 -0.064 -0.040 0.185 0.000 0.000 0.007
## -0.287 0.104 0.371 -0.027 0.003 0.035 0.000 0.000 0.002
## -0.017 0.077 0.002 0.076 -0.175 0.075 0.541 0.000 0.000
## -0.211 -0.038 -0.115 0.009 0.014 0.038 0.247 0.018 0.183
##
## Derivative matrix of expected statistics X by parameters:
##
## 1.707500e+01 5.026000e+00 2.688930e+02 6.173890e+02 2.600800e+01 2.064200e+01 -4.923270e+02 1.196568e+05 2.710100e+01
## 4.779000e+00 4.440000e+00 1.073280e+02 1.501020e+02 8.470000e+00 5.084000e+00 -2.280870e+02 5.267843e+04 9.411000e+00
## 1.035850e+02 4.350200e+01 1.974709e+03 3.569923e+03 1.643730e+02 1.186620e+02 -3.852396e+03 9.177115e+05 1.825970e+02
## 3.011520e+02 8.732400e+01 4.624091e+03 2.298131e+04 3.849290e+02 3.800650e+02 -7.402840e+03 1.537104e+06 4.514610e+02
## 1.308600e+01 4.696000e+00 2.179400e+02 3.981780e+02 2.992500e+01 1.582500e+01 -4.548220e+02 1.230208e+05 2.222700e+01
## 9.349000e+00 2.369000e+00 1.371500e+02 3.532990e+02 1.398000e+01 2.194900e+01 -2.551040e+02 5.459912e+04 1.430500e+01
## -2.291690e+02 -1.356970e+02 -5.045892e+03 -6.156208e+03 -4.153860e+02 -2.445460e+02 1.969863e+04 -4.498917e+06 -5.273470e+02
## 6.195011e+04 3.216710e+04 1.293768e+06 1.540487e+06 1.209733e+05 5.655805e+04 -4.500277e+06 1.993711e+09 1.338272e+05
## 1.405800e+01 5.801000e+00 2.543580e+02 4.785240e+02 2.264900e+01 1.624400e+01 -5.894430e+02 1.371955e+05 3.830800e+01
##
## Covariance matrix of X (correlations below diagonal):
##
## 2.196700e+01 8.277000e+00 3.729160e+02 7.595960e+02 3.399500e+01 2.530400e+01 -7.228110e+02 1.865815e+05 3.723200e+01
## 6.170000e-01 8.186000e+00 2.053630e+02 2.337560e+02 1.487800e+01 8.132000e+00 -4.344760e+02 1.077949e+05 1.790300e+01
## 9.030000e-01 8.140000e-01 7.772415e+03 1.186354e+04 6.071310e+02 3.985280e+02 -1.532150e+04 3.885040e+06 7.060330e+02
## 7.130000e-01 3.600000e-01 5.920000e-01 5.160993e+04 9.693990e+02 8.939060e+02 -1.975153e+04 4.957353e+06 1.195810e+03
## 8.480000e-01 6.080000e-01 8.050000e-01 4.990000e-01 7.316600e+01 3.868300e+01 -1.278434e+03 3.432997e+05 6.156700e+01
## 7.650000e-01 4.030000e-01 6.400000e-01 5.570000e-01 6.410000e-01 4.984100e+01 -7.926090e+02 1.813774e+05 4.218000e+01
## -6.730000e-01 -6.620000e-01 -7.580000e-01 -3.790000e-01 -6.520000e-01 -4.900000e-01 5.256816e+04 -1.206501e+07 -1.578561e+03
## 5.680000e-01 5.370000e-01 6.280000e-01 3.110000e-01 5.720000e-01 3.660000e-01 -7.500000e-01 4.917680e+09 3.926587e+05
## 7.900000e-01 6.230000e-01 7.970000e-01 5.240000e-01 7.160000e-01 5.940000e-01 -6.850000e-01 5.570000e-01 1.010100e+02