-
Notifications
You must be signed in to change notification settings - Fork 18
/
ch07_hw.R
500 lines (432 loc) · 16.2 KB
/
ch07_hw.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
library(rethinking)
library(ggplot2)
library(GGally)
library(dplyr)
#source("plot_bindings.R")
### Easy ####
# 7E1
# (1) Bread dough rises because of yeast.
# -- and amount of flour/eggs/"soure cream"/water (any other ingredients of the dough)
#
# (2) Education leads to higher income.
# -- but also <parents income> does matter, or just country. In different countries slope between education and income is be different
# (3) Gasoline makes a car go.
# in this example it's not obvious what is the predicted variable - let's assume it's speed
# -- volume of the engine or number of cylinders, or proxy variable like a model of the car
#
# 7E2+7E3.
# Which of the following explanations invokes an interaction?
# For each of the explanations in 7E2, write a linear model that expresses the stated relationship
# (1) Caramelizing onions requires cooking over low heat and making sure the onions do not dry out.
# caramelizing ~ heat + dryness + heat*dryness
# One can expect that for the higher temperature there are more chances for the onion to dry out, so I added interaction of those terms.
# (2) A car will go faster when it has more cylinders or when it has a better fuel injector.
# Both models - with and without interaction look reasonable for me.
# max_speed ~ n_cylinders + fuel_injector
# max_speed ~ n_cylinders + fuel_injector + n_cylinders*fuel_injector
# (3) Most people acquire their political beliefs from their parents, unless they get them instead from their friends.
# political_beliefs ~ parents_beliefs*(1-has_political_friends) + has_political_friends*friends_beliefs
# (4) Intelligent animal species tend to be either highly social or have manipulative appendages (hands, tentacles, etc.).
# Without any domain knowledge, I assume, that there is no interaction between social level and presence of manipulative appendages as evidence of intelligence.
# intelligence ~ social_level + has_manipulalative_appendages
### Medium ####
# 7M1
# Temperature is the main factor, shade and water depends on it.
# or there is an interaction between T and W, T and S, T and W and S
# 7M2
# bloom ~ is_temp_cold * (a + bW*w + bS*s + bWS*w*s)
# 7M3
# The simplest dataset contains two variables - "raven population size" and "wolf population size" measured across different areas.
# I expect that these variables are correlated. Also, I assume, this relation is non-linear. As with the increase of wolves population but constant amount of food on the area, wolves tend to eat all food not leaving anything to ravens.
# So hypothetical relation look like
# raven_pop_size ~ beta_wolf*wolf_pop_size +beta_wolf2*raven_pop_size^2 with beta_wolf2<0
# Extended data set would consist of 4 variables
# 1) raven population
# 2) wolves population
# 3) amount of potential food (herbivorous population in are)
# 4) area size
# Then I would expect model like
# raven_pop_size ~ a1 + (beta_food + beta_wolf*wolf_pop_size)*food, that explicitely states that slope on food depends from wolves population size
### Hard ####
# 7H1 + 7H2 ####
data(tulips)
d <- tulips
str(d)
pairs(d)
d$shade.c <- d$shade - mean(d$shade)
d$water.c <- d$water - mean(d$water)
d$bed.idx <- coerce_index(d$bed)
m7.8 <- map(
alist(
blooms ~ dnorm( mu , sigma ) ,
mu <- a + bW*water.c + bS*shade.c ,
a ~ dnorm( 130 , 100 ) ,
bW ~ dnorm( 0 , 100 ) ,
bS ~ dnorm( 0 , 100 ) ,
sigma ~ dunif( 0 , 100 )
) ,
data=d ,
start=list(a=mean(d$blooms),bW=0,bS=0,sigma=sd(d$blooms)) )
m7.9 <- map(
alist(
blooms ~ dnorm( mu , sigma ) ,
mu <- a + bW*water.c + bS*shade.c + bWS*water.c*shade.c ,
a ~ dnorm( 130 , 100 ) ,
bW ~ dnorm( 0 , 100 ) ,
bS ~ dnorm( 0 , 100 ) ,
bWS ~ dnorm( 0 , 100 ) ,
sigma ~ dunif( 0 , 100 )
) ,
data=d ,
start=list(a=mean(d$blooms),bW=0,bS=0,bWS=0,sigma=sd(d$blooms)) )
coeftab(m7.8,m7.9)
m7.10 <- map(
alist(
blooms ~ dnorm( mu , sigma ) ,
mu <- a[bed.idx] + bW*water.c + bS*shade.c + bWS*water.c*shade.c ,
a[bed.idx] ~ dnorm( 130 , 100 ) ,
bW ~ dnorm( 0 , 100 ) ,
bS ~ dnorm( 0 , 100 ) ,
bWS ~ dnorm( 0 , 100 ) ,
sigma ~ dunif( 0 , 100 )
) ,
data=d ,
start=list(a=c(mean(d$blooms),mean(d$blooms),mean(d$blooms)),bW=0,bS=0,bWS=0,sigma=sd(d$blooms)),
method="Nelder-Mead" ,
control=list(maxit=1e4))
coeftab(m7.8,m7.9, m7.10)
compare(m7.8,m7.9, m7.10)
samples <- extract.samples(m7.10)
str(samples)
hist(samples$a[,1], xlim=c(0,200), ylim=c(0, 1500), col=col.alpha('blue',0.3))
hist(samples$a[,2], add=T, col=col.alpha('red',0.3))
hist(samples$a[,3], add=T, col=col.alpha('yellow',0.3))
dens(samples$a[,1], xlim=c(0,200), col='blue')
dens(samples$a[,2], add=T, col='red')
dens(samples$a[,3], add=T, col='black')
dens(samples$a[,1]-samples$a[,2], col='blue')
dens(samples$a[,1]-samples$a[,3], add=T, col='red')
dens(samples$a[,2]-samples$a[,3], add=T, col='black')
d$is_first_bed <- as.integer(d$bed.idx!=1)+1
m7.11 <- map(
alist(
blooms ~ dnorm( mu , sigma ) ,
mu <- a[is_first_bed] + bW*water.c + bS*shade.c + bWS*water.c*shade.c ,
a[is_first_bed] ~ dnorm( 130 , 100 ) ,
bW ~ dnorm( 0 , 100 ) ,
bS ~ dnorm( 0 , 100 ) ,
bWS ~ dnorm( 0 , 100 ) ,
sigma ~ dunif( 0 , 100 )
) ,
data=d ,
start=list(a=c(mean(d$blooms),mean(d$blooms)),bW=0,bS=0,bWS=0,sigma=sd(d$blooms)),
method="Nelder-Mead" ,
control=list(maxit=1e4))
# Several executions of compare function below gave slightly different resutls for models' weights(!!!).
# Weight of the top model varies from 0.85 to 0.96
compare(m7.8, m7.9, m7.11)
coeftab(m7.8, m7.9, m7.10, m7.11)
# add interaction of water and shade with bed
m7.12 <- map(
alist(
blooms ~ dnorm( mu , sigma ) ,
mu <- a[bed.idx] + bW[bed.idx]*water.c + bS[bed.idx]*shade.c + bWS*water.c*shade.c ,
a[bed.idx] ~ dnorm( 130 , 100 ) ,
bW[bed.idx] ~ dnorm( 0 , 100 ) ,
bS[bed.idx] ~ dnorm( 0 , 100 ) ,
bWS ~ dnorm( 0 , 100 ) ,
sigma ~ dunif( 0 , 100 )
) ,
data=d ,
start=list(a=c(mean(d$blooms),mean(d$blooms),mean(d$blooms)),bW=0,bS=0,bWS=0,sigma=sd(d$blooms)),
method="Nelder-Mead" ,
control=list(maxit=1e4))
compare(m7.8,m7.9, m7.11, m7.12)
precis(m7.12, depth=2)
# 7H3 ####
data("rugged")
d <- rugged
d$log_gdp <- log( d$rgdppc_2000 )
d <- d[complete.cases(d$rgdppc_2000), ]
nrow(d)
d$rugged.c <- d$rugged - mean(d$rugged)
slope.sigma <- 10 #(!) try to make several runs varying this value(e.g. 0.1 correspondts to regularized priors and difference between full and ns model becomes smaller)
m7h3.full <- map(alist(
log_gdp ~ dnorm(mu, sigma),
mu <- a + bR*rugged.c + bA*cont_africa + rugged.c*cont_africa*bAR,
a ~ dnorm(8, 100),
bR ~ dnorm(0, slope.sigma),
bA ~ dnorm(0, slope.sigma),
bAR ~ dnorm(0, slope.sigma),
sigma ~ dunif(0, 10)
),
data=d)
precis(m7h3.full)
## plot predictions for Africa and not Africa
#### helper functions ####
predict_mu <- function(model, d.predict){
mu <- link(model, data=d.predict)
mu.mean <- apply(mu, 2, mean)
mu.pi <- apply(mu, 2, PI)
list(mean=mu.mean, pi=mu.pi)
}
plot_model_mu <- function(d.raw, d.predict, mu.pred, title){
plot(log_gdp ~ rugged.c, data=d.raw, col='blue', ylim=c(5,12), xlim=c(-2, 6))
lines(d.predict$rugged.c, mu.pred$mean, col='red')
shade(mu.pred$pi, d.predict$rugged.c)
mtext(title)
}
d.predict.af <- data.frame(rugged.c=seq(-2,6,by=0.1), cont_africa=1)
d.predict.naf <- data.frame(rugged.c=seq(-2,6,by=0.1), cont_africa=0)
mu7h3.full.af <- predict_mu(m7h3.full, d.predict.af)
mu7h3.full.naf <- predict_mu(m7h3.full, d.predict.naf)
par(mfrow=c(1,2))
plot_model_mu(d[d$cont_africa==1,], d.predict.af, mu7h3.full.af, 'Africa, full')
plot_model_mu(d[d$cont_africa==0,], d.predict.naf, mu7h3.full.naf, 'not Africa, full')
# fit model on data without Seychelles
d.ns <- d[d$country!='Seychelles',]
#slope.sigma <- 10
m7h3.ns <- map(alist(
log_gdp ~ dnorm(mu, sigma),
mu <- a + bR*rugged.c + bA*cont_africa + rugged.c*cont_africa*bAR,
a ~ dnorm(8, 100),
bR ~ dnorm(0, slope.sigma),
bA ~ dnorm(0, slope.sigma),
bAR ~ dnorm(0, slope.sigma),
sigma ~ dunif(0, 10)
),
data=d.ns)
precis(m7h3.ns)
mu7h3.ns.af <- predict_mu(m7h3.ns, d.predict.af)
mu7h3.ns.naf <- predict_mu(m7h3.ns, d.predict.naf)
par(mfrow=c(1,2))
plot_model_mu(d.ns[d.ns$cont_africa==1,], d.predict.af, mu7h3.ns.af, 'Africa, no Seychelles')
plot_model_mu(d.ns[d.ns$cont_africa==0,], d.predict.naf, mu7h3.ns.naf, 'not Africa, no Seychelles')
plot(coeftab(m7h3.full, m7h3.ns))
#compare(m7h3.full, m7h3.ns)
par(mfrow=c(1,1))
#plot Africa's only predictions
plot_model_mu(d[d$cont_africa==1,], d.predict.af, mu7h3.full.af, 'Africa full (red+grey) vs Africa withou Seychelles(yellow+green)')
lines(d.predict.af$rugged.c, mu7h3.ns.af$mean, col='yellow')
shade(mu7h3.ns.af$pi, d.predict.af$rugged.c, col=col.alpha('green'))
# compare distributions of slope for Africa countries in two models
m7h3.full.sample <- extract.samples(m7h3.full)
m7h3.ns.sample <- extract.samples(m7h3.ns)
m7h3.full.sample <- mutate(m7h3.full.sample, af_slope=bR+bAR)
m7h3.ns.sample <- mutate(m7h3.ns.sample, af_slope=bR+bAR)
summary(m7h3.full.sample$af_slope)
mean(m7h3.full.sample$af_slope>0)
summary(m7h3.ns.sample$af_slope)
mean(m7h3.ns.sample$af_slope>0)
summary(m7h3.full.sample$bR)
summary(m7h3.ns.sample$bR)
dens(m7h3.full.sample$af_slope, xlim=c(-0.3, 0.5), col='blue')
dens(m7h3.ns.sample$af_slope, add=T, col='red')
dens(m7h3.full.sample$af_slope-m7h3.ns.sample$af_slope, add=T, col='black')#not sure it's a correct procedure
# summary for 7H3 (a+b)
# Without Seychelles data point slope for African countries reduces almost twice but is still positive compared to non-African countries that have a negative slope.
# The use of strong regularised priors with sigma = 0.1 decreases all slopes and make differences between full and NoSeychelles(NS) models almost neglectable.
# Even for NS model there are 0.77 probability that slope for African countries is greater than zero.
# 7H3.c
slope.sigma <- 10
m7h3.ns.r <- map(alist(
log_gdp ~ dnorm(mu, sigma),
mu <- a + bR*rugged.c,
a ~ dnorm(8, 100),
bR ~ dnorm(0, slope.sigma),
sigma ~ dunif(0, 10)
),
data=d.ns)
m7h3.ns.ra <- map(alist(
log_gdp ~ dnorm(mu, sigma),
mu <- a + bR*rugged.c + bA*cont_africa,
a ~ dnorm(8, 100),
bR ~ dnorm(0, slope.sigma),
bA ~ dnorm(0, slope.sigma),
sigma ~ dunif(0, 10)
),
data=d.ns,
start=list(a=c(mean(d.ns$log_gdp)),bR=0,bA=0,sigma=sd(d.ns$log_gdp))
)
m7h3.ns <- map(alist(
log_gdp ~ dnorm(mu, sigma),
mu <- a + bR*rugged.c + bA*cont_africa + rugged.c*cont_africa*bAR,
a ~ dnorm(8, 100),
bR ~ dnorm(0, slope.sigma),
bA ~ dnorm(0, slope.sigma),
bAR ~ dnorm(0, slope.sigma),
sigma ~ dunif(0, 10)
),
data=d.ns)
compare(m7h3.ns.r, m7h3.ns.ra, m7h3.ns)
mu7h3.ns.af <- predict_mu(m7h3.ns, d.predict.af)
mu7h3.ns.naf <- predict_mu(m7h3.ns, d.predict.naf)
par(mfrow=c(3,2))
d.predict.af <- data.frame(rugged.c=seq(-2,6,by=0.1), cont_africa=1)
d.predict.naf <- data.frame(rugged.c=seq(-2,6,by=0.1), cont_africa=0)
for(model in list(m7h3.ns.r, m7h3.ns.ra, m7h3.ns)){
mu.af <- predict_mu(model, d.predict.af)
plot_model_mu(d.ns[d.ns$cont_africa==1,], d.predict.af, mu.af, 'Africa, no Seychelles')
m.naf <- predict_mu(model, d.predict.naf)
plot_model_mu(d.ns[d.ns$cont_africa==0,], d.predict.naf, m.naf, 'not Africa, no Seychelles')
}
par(mfrow=c(1,1))
coeftab(m7h3.ns.r, m7h3.ns.ra, m7h3.ns)
compare(m7h3.ns.r, m7h3.ns.ra, m7h3.ns)
### averaged across models
mu.ensemble <- ensemble(m7h3.ns.r, m7h3.ns.ra, m7h3.ns, data = d.predict.af)
mu.mean <- apply(X = mu.ensemble$link, MARGIN = 2, FUN = mean)
mu.PI <- apply(X = mu.ensemble$link, MARGIN = 2, FUN = PI)
plot_model_mu(d.ns[d.ns$cont_africa==1,], d.predict.af, list(mean=mu.mean, pi=mu.PI), 'Africa, no Seychelles')
#### 7H4 ####
data(nettle)
d <- tbl_df(nettle)
d <- d %>% mutate(
lang.per.cap = num.lang / k.pop,
log_pop = log(k.pop),
log_area = log(area),
log_lang.per.cap = log(lang.per.cap),
pop_density = k.pop/area,
log_area_c = log_area-mean(log_area),
mgc_c = mean.growing.season - mean(mean.growing.season)
)
d
ggpairs(select(d,-country))
d <- as.data.frame(d)
dens(log(d$lang.per.cap))
hist(log(d$lang.per.cap),breaks = 20)
hist(d$mgc_c)
hist(d$log_area_c)
slope.sigma <- 10
m7h4.1 <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.area*log_area_c,
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.area ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d)
precis(m7h4.1)
# I'm just curious how priors influence coefficients
slope.sigma <- .1
m7h4.1rp <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.area*log_area_c,
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.area ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d)
precis(m7h4.1rp)
compare(m7h4.1, m7h4.1rp)
coeftab(m7h4.1, m7h4.1rp)
hist(d$sd.growing.season)
d$sdgs_c <- d$sd.growing.season - mean(d$sd.growing.season)
m7h4.2 <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.sds*sdgs_c + b.area*log_area_c,
a ~ dnorm(-5, 100),
b.sds ~ dnorm(0, slope.sigma),
b.area ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d)
precis(m7h4.2)
compare(m7h4.1, m7h4.2)
m7h4.3 <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.sds*sdgs_c,# + b.area*log_area_c,
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.sds ~ dnorm(0, slope.sigma),
# b.area ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d)
precis(m7h4.3)
compare(m7h4.1, m7h4.2, m7h4.3)
m7h4.3i <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.sds*sdgs_c + b.ms.sds*mgc_c*sdgs_c,
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.sds ~ dnorm(0, slope.sigma),
b.ms.sds ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d)
precis(m7h4.3i)
compare(m7h4.1, m7h4.2, m7h4.3, m7h4.3i)
##
plot_model_mu_mgc <- function(d.raw, d.predict, mu.pred, title){
plot(log_lang.per.cap ~ mgc_c, data=d.raw, col='blue', ylim=c(-10,0), xlim=c(-7.1, 5))
lines(d.predict$mgc_c, mu.pred$mean, col='red')
shade(mu.pred$pi, d.predict$mgc_c)
mtext(title)
}
plot_model_mu_sds <- function(d.raw, d.predict, mu.pred, title){
plot(log_lang.per.cap ~ sdgs_c, data=d.raw, col='blue', ylim=c(-10,0), xlim=c(-2, 4.1))
lines(d.predict$sdgs_c, mu.pred$mean, col='red')
shade(mu.pred$pi, d.predict$sdgs_c)
mtext(title)
}
## tryptych for ~mgc_c
summary(d$sdgs_c)
par(mfrow=c(1,4))
mgc_c.seq <- seq(min(d$mgc_c),max(d$mgc_c),by=0.1)
model <- m7h4.3i
model.name <- ' m7h4.3i'
left_q <- 0
for(right_q in c(0.25, 0.5, 0.75, 1)){
qq <- quantile(d$sdgs_c, probs=c(left_q, right_q))
lval = qq[1]
rval = qq[2]
if(right_q!=1){
d.raw <- d[(d$sdgs_c >= lval) & (d$sdgs_c < rval),]
} else {
d.raw <- d[(d$sdgs_c >= lval) & (d$sdgs_c <= rval),]
}
sdg_c = mean(d.raw$sdgs_c)
d.predict=data.frame(mgc_c=mgc_c.seq, sdgs_c=sdg_c, log_area_c=0)
mu <- predict_mu(model, d.predict)
plot_model_mu_mgc(d.raw, d.predict, mu, paste0(c(model.name,'sdgs_c=',sdg_c),collapse = ' '))
left_q <- right_q
}
sdgs_c.seq <- seq(min(d$sdgs_c),max(d$sdgs_c),by=0.1)
model <- m7h4.2
model.name <- 'm7h4.2'
for(mgc_c in c(-7, 0, 4.9)){
d.predict=data.frame(mgc_c=mgc_c, sdgs_c=sdgs_c.seq, log_area_c=0)
mu <- predict_mu(model, d.predict)
plot_model_mu_sds(d, d.predict, mu, paste0(c(model.name,'mgc_c=',mgc_c),collapse = ' '))
}
###### add population density to models and compare them with already fitted #####
m7h4.4d <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.dens*log(pop_density),
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.dens ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d, method="Nelder-Mead" ,
control=list(maxit=1e4))
precis(m7h4.4d)
m7h4.3i.d <- map(alist(
log_lang.per.cap ~ dnorm(mu, sigma),
mu <- a + b.ms*mgc_c + b.sds*sdgs_c + b.ms.sds*mgc_c*sdgs_c+ b.dens*log(pop_density),
a ~ dnorm(-5, 100),
b.ms ~ dnorm(0, slope.sigma),
b.sds ~ dnorm(0, slope.sigma),
b.ms.sds ~ dnorm(0, slope.sigma),
b.dens ~ dnorm(0, slope.sigma),
sigma~dunif(0,10)
),
data=d,
method="Nelder-Mead" ,
control=list(maxit=1e5))
precis(m7h4.3i.d)
compare(m7h4.1, m7h4.4d, m7h4.3, m7h4.3i, m7h4.3i.d)
plot(coeftab(m7h4.1, m7h4.4d, m7h4.3, m7h4.3i, m7h4.3i.d))