-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visualisations.R
228 lines (153 loc) · 6.65 KB
/
Visualisations.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
require(stargazer);
require(moments)
#==== Basic variables ====
fit <- lm(radicality ~ reg_div + continent + applicant_type ,data = ApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(radicality ~ continent + applicant_type ,data = ApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(radicality ~ up_reg_div ,data = ApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(radicality ~ reg_div + I(reg_div^2),data = ApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(fwd_cits5_xy ~ radicality, data = uApplnStats, na.action = na.omit)
summary(fit)
#filter for eu
EuStats <- sqldf('select * from ApplnStats WHERE continent = "EU"')
fit <- lm(radicality ~ up_reg_div ,data = EuStats, na.action = na.omit)
summary(fit)
#==== Region level regressions ====
# requires eRegstats dataframe as joined in 'Join_patent_statistics.R'
fit <- lm(avg_radicality ~ reg_div ,data = eRegStats, na.action = na.omit)
summary(fit)
fit <- lm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit)
summary(fit)
## regionality
fit <- lm(avg_regionality ~ reg_div ,data = eRegStats, na.action = na.omit)
summary(fit)
fit <- lm(avg_regionality ~ up_reg_div ,data = eupRegStats, na.action = na.omit)
summary(fit)
fit <- lm(radicality ~ up_regionality ,data = uApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(radicality ~ regionality ,data = uApplnStats, na.action = na.omit)
summary(fit)
fit <- lm(avg_regionality ~ avg_radicality ,data = eRegStats, na.action = na.omit)
summary(fit)
## knowledge base diversity
data <- na.omit(uApplnStats[c('radicality', 'back_cit_div', 'applicant_type')])
fit <- lm(log(radicality) ~ back_cit_div + applicant_type, data = data)
summary(fit)
fit0 <- lm(log(radicality) ~ applicant_type, data = data)
summary(fit0)
html <- stargazer(fit0, fit, type="html", single.row=TRUE, column.labels=c("control","model"))
write(html, file = paste0('export/regressiontable',9999,'.html'))
#==== Regional regression with oecd controls ====
# requires eeRegStats from 'join_OECD_stats.R'
data <- eeRegStats[,sapply(eeRegStats, is.numeric)] #remove region names etc.
data$avg_impact <- NULL
data$avg_regionality <- NULL
## stepAIC
# Idenfity variables with multicolliniarity (with vif value > 10)
require(usdm)
datacorr <- rcorr(as.matrix(data))
View(datacorr$r)
datacoll <- vif(data)
# colsToKeep <- as.character(datacoll[datacoll$VIF<10,1]) # not applicable anymore
# data <- data[,colsToKeep]
rfit <- lm(avg_radicality ~ reg_div + ., na.omit(data)) # Original fit
rfit1 <- stepAIC(rfit, direction = "both")
modelssum <- summary(rfit1)
### Gives model
modelssum$call
modelssum
### Control
rfit0 <- lm(formula = avg_radicality ~ npatents + COMPANY +
INDIVIDUAL, data = na.omit(data))
### Only reg_div
rfit2 <- lm(formula = avg_radicality ~ reg_div, data = na.omit(data))
### all
rfit3 <- lm(formula = avg_radicality ~ reg_div +. , data = na.omit(data))
# make a nice table
html <- stargazer(rfit0, rfit1, rfit2, rfit3, type="html", single.row=TRUE, column.labels=c("control","model"))
write(html, file = paste0('export/regressiontable',1,'.html'))
###### now for the upRegStats
data <- eeUpRegStats[,sapply(eeUpRegStats, is.numeric)] #remove region names etc.
data$avg_impact <- NULL
data$avg_regionality <- NULL
data$RD_EXP_TOT_PERC <-data$RD_PER_TOT_PERC <- data$INMIG_REL <- NULL
names(data)[2] <- 'reg_div'
datacorr <- rcorr(as.matrix(data))
View(datacorr$r)
datacoll <- vif(data)
#colsToKeep <- as.character(datacoll[datacoll$VIF<10,1])
#data <- data[,colsToKeep]
fit <- lm(avg_radicality ~ reg_div + ., data = data[])
summary(fit)
# Now without reg div
#fit <- lm(avg_radicality ~ .+.^2, data = data[,-2])
#summary(fit)
# Now without regionality
fit <- lm(avg_radicality ~ ., data = data[,-4])
summary(fit)
## stepAIC of first fit
# Idenfity variables with multicolliniarity (with vif value > 10)
require(usdm)
datacoll <- vif(data)
colsToKeep <- as.character(datacoll[datacoll$VIF<10,1])
data <- data[,colsToKeep]
fit <- lm(avg_radicality ~ reg_div + ., na.omit(data)) # Original fit
upfit1 <- stepAIC(fit, direction = "both")
modelssum <- summary(upfit1)
### Gives model
modelssum$call
### Control
upfit0 <- lm(formula = avg_radicality ~ npatents + EDU_LF_ISCED_56_PERC +
GDP_PC_REAL_PPP + POP_DEN + GOVNONPROFIT + UNIVERSITY + INDIVIDUAL,
data = na.omit(data))
summary(upfit0)
stargazer(upfit0, upfit1, rfit0, rfit1, type="html",
single.row=TRUE,
column.labels=c("control TL2","model TL2", "control TL3","model TL3" ),
out = paste0('export/regressiontable',2,'.html'),
covariate.labels = c('Region diversity', 'N patents', 'Education level workforce', 'GDP per capita', 'Population density','applicant_type GOV NON-PROFIT', 'applicant_type UNIVERSITY', 'applicant_type COMPANY', 'applicant_type INDIVIDUAL'),
dep.var.labels = c('Average Radicality'),
ord.intercepts = FALSE,
omit = c('Constant'))
################################################################################
#==== Generalized Linear Models // log link functions ====
fit <- glm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit, family =poisson(link = "log"))
summary(fit)
fit <- glm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit, family =gaussian(link = "identity"))
summary(fit)
fit <- glm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit, family =Gamma(link="inverse"))
summary(fit)
fit <- glm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit, family =binominal())
summary(fit)
fit <- glm(avg_radicality ~ up_reg_div ,data = eupRegStats, na.action = na.omit, family =binominal())
summary(fit)
#===== Old regressions ====
#==== with extended controls ====
#all
fit <- lm(tech_rad_rs ~ reg_div + npatents + applicant_type + EE + ME + Ins + Oth, data=ApplnStats, na.action = na.omit)
summary(fit)
# 0.1035
#only control
fit <- lm(tech_rad_rs ~ applicant_type + EE + ME + Ins + Oth, data=allStat, na.action = na.omit)
summary(fit)
#0.1037
#all including regionality
fit <- lm(tech_rad_rs ~ reg_div + regionality + npatents + applicant_type + EE + ME + Ins + Oth, data=allStat, na.action = na.omit)
summary(fit)
#0.1015
vcov(fit) # covariance matrix for model parameters
influence(fit) # regression diagnostics
==== Measuring skewness ====
skewness(log(na.omit(ApplnStats$radicality)))
kurtosis(log(na.omit(ApplnStats$radicality)))
# technolgical relatedness
map <- readRDS(file = 'maps/jaccard/allyear/techmap_2012.RDa')
skewness(as.vector(map))
# knowledge base diversity
skewness(na.omit(ApplnStats$back_cit_div))
kurtosis(na.omit(ApplnStats$back_cit_div))
#impact
skewness(na.omit(ApplnStats$fwd_cits5_xy))