# read the Seoul data set and create lag variables
data(mort)
seoul = read6city(mort, 11)
seoul_lag = lagdata(seoul, c("meantemp", "mintemp", "meanpm10", "meanhumi"), 5)
# find a optimal threshold and conduct piecewise linear regression
mythresh = threshpt(nonacc ~ meantemp_m3 + meanpm10_m2 + meanhumi + ns(sn, 4*10) + factor(dow),
expvar = "meantemp_m3", family = "poisson", data = seoul_lag,
startrng = 23, endrng = 33, searchunit = 0.2)
# obtain plots
plot(mythresh, select = 1, se = TRUE, expdf=8, col.value = "blue", col.ci = "light blue")
plot(mythresh, select = 2, se = FALSE, col.vline = "orange")
plot(mythresh, select = 3, pch = 1, pch.preval = 2)
plot(mythresh, select = 4)
Run the code above in your browser using DataLab