#RSiena
#start with clean workspace
rm(list=ls())
#load dataobjects
load("./data/descriptives/RU_net_array_sym.RData")
load("./data/descriptives/RUpub_dfv2.RData")
load("./data/descriptives/RU_dfv2.RData")
load("./data/names_staff_cit_v20221006.RData")
library(RSiena)
library(tidyverse)
names_staff_cit %>%
filter(gs_id %in% soc_df$gs_id) -> RU_staff_cit
save(RU_staff_cit, file="./data/descriptives/RU_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(RU_staff_cit[(RU_staff_cit$gs_id == soc_df$gs_id[i]) & RU_staff_cit$year>=2016 & RU_staff_cit$year<=2017,])
pubsw2[i] <- nrow(RU_staff_cit[(RU_staff_cit$gs_id == soc_df$gs_id[i]) & RU_staff_cit$year>=2018 & RU_staff_cit$year<=2019,])
pubsw3[i] <- nrow(RU_staff_cit[(RU_staff_cit$gs_id == soc_df$gs_id[i]) & RU_staff_cit$year>=2020 & RU_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(myeff1)
### Step 3: get initial description
print01Report(mydata1, modelname = "./data/results/RU_init")
### Step4: specify model
myeff1 <- includeEffects(myeff1, degPlus) #popularity
## effectName include fix test initialValue parm
## 1 degree act+pop TRUE FALSE FALSE 0 1
myeff1 <- includeEffects(myeff1, transTriads) #number of transitive patterns in i's relationships
## effectName include fix test initialValue parm
## 1 transitive triads TRUE FALSE FALSE 0 0
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 = "RU_init")
## If you use this algorithm object, siena07 will create/use an output file RU_init.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 1.2152 ( 0.4125 )
## 0.2 Rate parameter period 2 2.8213 ( 1.1543 )
##
## Other parameters:
## 1. eval degree (density) -2.4204 ( 0.4934 ) 0.0451
## 2. eval transitive triads 0.8953 ( 0.3366 ) -0.0122
## 3. eval degree act+pop 0.1224 ( 0.0588 ) 0.0318
## 4. eval div_net abs. difference -0.0332 ( 0.0117 ) 0.0454
##
## Overall maximum convergence ratio: 0.1085
##
##
## Total of 1988 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 1.2152 ( 0.4125 )
## 0.2 Rate parameter period 2 2.8213 ( 1.1543 )
##
## Other parameters:
## 1. eval degree (density) -2.4204 ( 0.4934 ) 0.0451
## 2. eval transitive triads 0.8953 ( 0.3366 ) -0.0122
## 3. eval degree act+pop 0.1224 ( 0.0588 ) 0.0318
## 4. eval div_net abs. difference -0.0332 ( 0.0117 ) 0.0454
##
## Overall maximum convergence ratio: 0.1085
##
##
## Total of 1988 iteration steps.
##
## Covariance matrix of estimates (correlations below diagonal)
##
## 0.243 0.037 -0.024 -0.002
## 0.225 0.113 -0.011 0.000
## -0.822 -0.563 0.003 0.000
## -0.307 0.008 -0.018 0.000
##
## Derivative matrix of expected statistics X by parameters:
##
## 47.254 34.542 1239.830 1433.528
## 33.489 44.645 1071.541 985.930
## 454.795 405.813 13549.849 13697.429
## 629.834 440.607 16290.420 33681.365
##
## Covariance matrix of X (correlations below diagonal):
##
## 82.823 75.573 2376.090 2454.300
## 0.839 97.988 2461.779 2159.776
## 0.960 0.914 73985.320 69423.779
## 0.846 0.684 0.801 101624.770
mydata2 <- sienaDataCreate(net, div_net, div_ego, gender, pub_first, pubs, total_cites)
### Step 2: create effects structure
myeff2 <- getEffects(mydata2)
#effectsDocumentation(myeff2)
### Step 3: get initial description
print01Report(mydata2, modelname = "./data/results/soc_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
myeff2 <- includeEffects(myeff2, sameX,interaction1="div_ego")
## effectName include fix test initialValue parm
## 1 same div_ego TRUE FALSE FALSE 0 0
myeff2 <- includeEffects(myeff2, sameX,interaction1="gender")
## effectName include fix test initialValue parm
## 1 same gender TRUE FALSE FALSE 0 0
myeff2 <- includeEffects(myeff2, 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
myeff2 <- includeEffects(myeff2, egoPlusAltX,interaction1="total_cites")
## effectName include fix test initialValue parm
## 1 total_cites ego and alt TRUE FALSE FALSE 0 0
myeff2 <- includeEffects(myeff2, 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 = "RU_init2")
## If you use this algorithm object, siena07 will create/use an output file RU_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 1.1693 ( 0.3894 )
## 0.2 Rate parameter period 2 2.6544 ( 0.8457 )
##
## Other parameters:
## 1. eval degree (density) -1.8804 ( 0.6790 ) 0.0645
## 2. eval transitive triads 1.2680 ( 0.3694 ) -0.0006
## 3. eval degree act+pop 0.0173 ( 0.0731 ) 0.0394
## 4. eval div_net abs. difference -0.0356 ( 0.0129 ) 0.0160
## 5. eval same div_ego 0.0627 ( 0.5084 ) 0.0555
## 6. eval same gender -0.3148 ( 0.3261 ) 0.0319
## 7. eval pub_first ego and alt 0.0458 ( 0.0232 ) -0.0415
## 8. eval total_cites ego and alt 0.0002 ( 0.0001 ) 0.0302
## 9. eval pubs ego and alt 0.0881 ( 0.2364 ) 0.0250
##
## Overall maximum convergence ratio: 0.1431
##
##
## Total of 2551 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 1.1693 ( 0.3894 )
## 0.2 Rate parameter period 2 2.6544 ( 0.8457 )
##
## Other parameters:
## 1. eval degree (density) -1.8804 ( 0.6790 ) 0.0645
## 2. eval transitive triads 1.2680 ( 0.3694 ) -0.0006
## 3. eval degree act+pop 0.0173 ( 0.0731 ) 0.0394
## 4. eval div_net abs. difference -0.0356 ( 0.0129 ) 0.0160
## 5. eval same div_ego 0.0627 ( 0.5084 ) 0.0555
## 6. eval same gender -0.3148 ( 0.3261 ) 0.0319
## 7. eval pub_first ego and alt 0.0458 ( 0.0232 ) -0.0415
## 8. eval total_cites ego and alt 0.0002 ( 0.0001 ) 0.0302
## 9. eval pubs ego and alt 0.0881 ( 0.2364 ) 0.0250
##
## Overall maximum convergence ratio: 0.1431
##
##
## Total of 2551 iteration steps.
##
## Covariance matrix of estimates (correlations below diagonal)
##
## 0.461 0.041 -0.028 -0.002 -0.200 -0.043 -0.002 0.000 0.016
## 0.163 0.136 -0.014 0.000 0.004 -0.011 0.002 0.000 -0.009
## -0.566 -0.532 0.005 0.000 -0.003 -0.001 0.000 0.000 0.000
## -0.236 -0.084 -0.082 0.000 0.000 0.001 0.000 0.000 0.000
## -0.580 0.021 -0.078 0.016 0.258 -0.003 0.001 0.000 -0.037
## -0.194 -0.093 -0.031 0.147 -0.018 0.106 0.000 0.000 0.005
## -0.153 0.268 -0.030 -0.072 0.078 0.006 0.001 0.000 0.001
## -0.009 0.404 -0.315 -0.045 0.091 -0.034 0.880 0.000 0.000
## 0.101 -0.107 -0.016 0.022 -0.307 0.070 0.200 0.078 0.056
##
## Derivative matrix of expected statistics X by parameters:
##
## 3.711400e+01 3.012500e+01 9.992880e+02 1.150768e+03 7.012500e+01 4.295200e+01 -1.040120e+03 3.456842e+05 4.636300e+01
## 2.854300e+01 4.360700e+01 9.382000e+02 8.761210e+02 5.604200e+01 3.575700e+01 -9.868200e+02 2.864013e+05 4.637200e+01
## 3.599660e+02 3.647970e+02 1.130031e+04 1.109270e+04 6.935560e+02 4.267900e+02 -1.281498e+04 4.211029e+06 5.113830e+02
## 5.666130e+02 4.821870e+02 1.537632e+04 3.046056e+04 1.069621e+03 6.081380e+02 -1.466305e+04 5.032479e+06 7.196310e+02
## 3.462300e+01 3.042700e+01 9.682070e+02 1.053388e+03 7.431700e+01 4.027200e+01 -1.087904e+03 3.488846e+05 5.049600e+01
## 1.895600e+01 1.759000e+01 5.347580e+02 5.491670e+02 3.610900e+01 4.046800e+01 -6.739220e+02 2.138217e+05 2.473400e+01
## -5.486200e+02 -6.007710e+02 -1.998699e+04 -1.572373e+04 -1.097891e+03 -7.289460e+02 4.313638e+04 -1.298326e+07 -1.113650e+03
## 1.874617e+05 1.808152e+05 6.769213e+06 5.501203e+06 3.680817e+05 2.399755e+05 -1.307648e+07 4.490909e+09 3.379523e+05
## 2.331800e+01 2.693600e+01 7.663290e+02 6.916660e+02 5.123400e+01 2.679900e+01 -1.109857e+03 3.321675e+05 8.015400e+01
##
## Covariance matrix of X (correlations below diagonal):
##
## 5.218300e+01 5.552400e+01 1.556838e+03 1.589762e+03 9.964700e+01 6.298200e+01 -1.788948e+03 5.702100e+05 7.645900e+01
## 8.060000e-01 9.101700e+01 1.965728e+03 1.608637e+03 1.108120e+02 7.058300e+01 -2.214449e+03 6.698391e+05 9.924000e+01
## 9.390000e-01 8.970000e-01 5.271305e+04 4.591793e+04 3.042447e+03 1.894536e+03 -6.296173e+04 2.044606e+07 2.560198e+03
## 8.010000e-01 6.140000e-01 7.280000e-01 7.552933e+04 3.002693e+03 1.879496e+03 -5.049698e+04 1.632909e+07 2.302030e+03
## 9.570000e-01 8.060000e-01 9.190000e-01 7.580000e-01 2.079280e+02 1.204240e+02 -3.602269e+03 1.138700e+06 1.597300e+02
## 8.280000e-01 7.030000e-01 7.840000e-01 6.500000e-01 7.930000e-01 1.108620e+02 -2.430367e+03 7.479646e+05 9.334300e+01
## -7.290000e-01 -6.830000e-01 -8.070000e-01 -5.410000e-01 -7.350000e-01 -6.790000e-01 1.154094e+05 -3.474406e+07 -3.468782e+03
## 7.270000e-01 6.470000e-01 8.210000e-01 5.470000e-01 7.280000e-01 6.550000e-01 -9.420000e-01 1.177819e+10 1.058415e+06
## 7.160000e-01 7.040000e-01 7.540000e-01 5.670000e-01 7.490000e-01 6.000000e-01 -6.910000e-01 6.600000e-01 2.184390e+02