
Martijn Wieling
Computational Linguistics Research Group
R
codefamily="binomial"
R
: plogis(x)
mgcv
version 1.8.16)geo <- bam(NotStd ~ s(Lon, Lat, k = 30), data = tuscan, family = "binomial", discrete = T)
summary(geo)
#
# Family: binomial
# Link function: logit
#
# Formula:
# NotStd ~ s(Lon, Lat, k = 30)
#
# Parametric coefficients:
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -0.2474 0.0033 -75.1 <2e-16 ***
# ---
# Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#
# Approximate significance of smooth terms:
# edf Ref.df Chi.sq p-value
# s(Lon,Lat) 28.2 29 1591 <2e-16 ***
# ---
# Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#
# R-sq.(adj) = 0.0042 Deviance explained = 0.312%
# fREML = 6.1609e+05 Scale est. = 1 n = 384454
fvisgam(geo, view = c("Lon", "Lat"), too.far = 0.045, main = "", rm.ranef = T)
geo2 <- bam(NotStd ~ s(km.e, Lat), data = tuscan, family = "binomial", discrete = T)
fvisgam(geo2, view = c("km.e", "Lat"), too.far = 0.045, main = "", rm.ranef = T)
geo3 <- bam(NotStd ~ te(km.e, Lat, k = c(6, 6)), data = tuscan, family = "binomial", discrete = T)
fvisgam(geo3, view = c("km.e", "Lat"), too.far = 0.045, main = "", rm.ranef = T)
te()
, which can model an \(N\)-way non-linear interaction:te(Lon, Lat, ConceptFreq, d=c(2,1))
te(Lon, Lat, ConceptFreq, YearBirth, d=c(2,1,1))
system.time(
m <- bam(NotStd ~ te(Lon, Lat, ConceptFreq.log.z, SpeakerBirthYear.z, d=c(2,1,1)) +
CommunitySize.log.z + SpeakerJob_Farmer + SpeakerEduLevel.log.z + SpeakerIsMale +
s(Speaker,bs="re") + s(Location,bs="re") + s(Concept,bs="re") +
s(Concept,CommunityRecordingYear.z,bs="re") + s(Concept,CommunitySize.log.z,bs="re") +
s(Concept,CommunityAvgIncome.log.z,bs="re") + s(Concept,CommunityAvgAge.log.z,bs="re") +
s(Concept,SpeakerJob_Farmer,bs="re") + s(Concept,SpeakerJob_Executive_AuxiliaryWorker,bs="re") +
s(Concept,SpeakerEduLevel.log.z,bs="re") + s(Concept,SpeakerIsMale,bs="re"),
data=tuscan, family="binomial", discrete=T, nthreads=4)
)
# user system elapsed
# 2322.5 21.1 701.3
smry <- summary(m) # takes 10 minutes to calculate
smry$p.table
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -0.4282 0.1264 -3.39 7.08e-04
# CommunitySize.log.z -0.0629 0.0223 -2.82 4.87e-03
# SpeakerJob_Farmer 0.0449 0.0169 2.66 7.81e-03
# SpeakerEduLevel.log.z -0.0678 0.0126 -5.38 7.29e-08
# SpeakerIsMale 0.0378 0.0128 2.95 3.18e-03
head(smry$s.table, 1)
# edf Ref.df Chi.sq p-value
# te(SpeakerBirthYear.z,ConceptFreq.log.z,Lon,Lat) 221 265 3270 0
# chance for a male farmer in a
# very small village (z-scored
# population size = -2) for
# which the location is unknown
# with a very low education
# level (z-score = -2) to use a
# non-standard lexical form
(logit <- coef(m)["(Intercept)"] +
coef(m)["SpeakerIsMale"] +
coef(m)["SpeakerJob_Farmer"] +
-2 * coef(m)["CommunitySize.log.z"] +
-2 * coef(m)["SpeakerEduLevel.log.z"])
# (Intercept)
# -0.0841
plogis(logit) # was: 0.438 (43.8%)
# (Intercept)
# 0.479
tail(smry$s.table, 11) # last 11 smooths are ranefs
# edf Ref.df Chi.sq p-value
# s(Speaker) 97.1 2005 106 9.40e-03
# s(Location) 175.0 209 5642 1.33e-96
# s(Concept) 167.0 168 436864 0.00e+00
# s(CommunityRecordingYear.z,Concept) 158.9 170 155893 4.88e-181
# s(CommunitySize.log.z,Concept) 149.9 169 29991 2.41e-111
# s(CommunityAvgIncome.log.z,Concept) 158.0 170 143207 1.75e-160
# s(CommunityAvgAge.log.z,Concept) 154.4 170 110722 5.80e-195
# s(SpeakerJob_Farmer,Concept) 86.1 169 26572 1.27e-07
# s(SpeakerJob_Executive_AuxiliaryWorker,Concept) 53.3 170 3319 8.07e-04
# s(SpeakerEduLevel.log.z,Concept) 139.1 169 9377 8.05e-49
# s(SpeakerIsMale,Concept) 85.4 169 112400 6.55e-11
s()
to model two-dimensional interactions on the same scalete()
family="binomial"
)Thank you for your attention!