教育支出对犯罪的影响,多层次混合模式结构

时间:2019-06-28 19:57:34

标签: r time-series mixed-models

我正在研究每个学区的教育支出对这些学区在15年内服务的城镇中犯罪率的影响。 (DV在这15年中对城市/城镇犯罪数据进行了1,676,191次观测。)

从技术上讲,城市与学区交叉,因为一个城市可能会同时进入多个学区。这意味着一个城市的每个学生的支出可能有多个价值。但是,学区与县重叠。

城市嵌套在县内,但是鉴于每个城市/城镇都有不同的PLACE_ID,我的理解是,这可以表示为(1 | PLACE_ID)+(1 | COUNTY_ID)或(1 | PLACE_ID / COUNTY_ID)。

我对混合效应模型非常熟悉,并且浏览了诸如此类的清晰而翔实的帖子:https://stats.stackexchange.com/questions/228800/crossed-vs-nested-random-effects-how-do-they-differ-and-how-are-they-specified;但是,对于是否可以创建像下面这样的交叉效果模型,我仍然有些困惑:

glmer.total <- glmer(CRIME_TOTAL ~ cent.log.pop + cent.log.pop.dens + year + cent.log.unemployment_rate + cent.schooldist.prop5.17.pov + cent.log.per.cap + diff.dem + cent.log.enforcement +cent.EXP_STUDENT + (year|PLACE_ID/COUNTY_ID) + (year|full_district_id) + (1|STATE), family = "poisson", control = glmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), REML = FALSE, total.years, na.action = "na.omit")

变量居中并记录:每个城市的流行率,每个城市的流行密度,年份,每个县的失业率,每个学区贫困儿童的比例,每个县的人均收入,那些在每个县的总统选举中投票给民主党人,每个城市/城镇的日志执行,每个学生/ 1000(每个学区)的集中支出的人。 “ PLACE_ID”对应于城镇,“ COUNTY_ID”对应于县,“ full_district_id”对应于学区和州。

  • 我需要选择按城市平均每年支出,还是 上面的代码合法吗?我收到以下错误:
extra argument(s) ‘REML’ disregardedError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GHrule(0L), compDev = compDev,  : 
  (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate

我提供了以下数据的简短摘要(但仅选择了一些变量以使其变得更小)。

谢谢!

structure(list(STATE = c("alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama", 
"alabama", "alabama", "alabama", "alabama"), state = c("AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", 
"AL"), full_district_id = c("0100510", "0100510", "0100510", 
"0100510", "0100090", "0100540", "0101860", "0102635", "0102760", 
"0100090", "0100540", "0101860", "0102635", "0102760", "0100090", 
"0100540", "0101860", "0102635", "0102760", "0100090", "0100540", 
"0101860", "0102635", "0102760", "0100090", "0100540", "0101860", 
"0102635", "0102760", "0100090", "0100540", "0101860", "0102635", 
"0102760", "0100090", "0100540", "0101860", "0102635", "0102760", 
"0100090", "0100540", "0101860", "0102635", "0102760", "0100090", 
"0100540", "0101860", "0102635", "0102760", "0100090", "0100540", 
"0101860", "0102635", "0102760", "0100090", "0100540", "0101860", 
"0102635", "0102760", "0100090", "0100540", "0101860", "0102635", 
"0102760", "0100090", "0100540", "0101860", "0102635"), SCHOOL_DISTRICT.x = c("butler county school district", 
"butler county school district", "butler county school district", 
"butler county school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district", "piedmont city school district", 
"anniston city school district", "calhoun county school district", 
"jacksonville city school district", "oxford city school district", 
"piedmont city school district", "anniston city school district", 
"calhoun county school district", "jacksonville city school district", 
"oxford city school district"), COUNTY = c("butler ", "butler ", 
"butler ", "butler ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", 
"calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun ", "calhoun "
), year = c(2006, 2007, 2008, 2009, 2006, 2006, 2006, 2006, 2006, 
2007, 2007, 2007, 2007, 2007, 2008, 2008, 2008, 2008, 2008, 2009, 
2009, 2009, 2009, 2009, 2010, 2010, 2010, 2010, 2010, 2011, 2011, 
2011, 2011, 2011, 2012, 2012, 2012, 2012, 2012, 2013, 2013, 2013, 
2013, 2013, 2014, 2014, 2014, 2014, 2014, 2015, 2015, 2015, 2015, 
2015, 2016, 2016, 2016, 2016, 2016, 2017, 2017, 2017, 2017, 2017, 
2007, 2007, 2007, 2007), COUNTY_ID = c("01013", "01013", "01013", 
"01013", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015", "01015", "01015", "01015", "01015", "01015", 
"01015", "01015"), SCHOOL_DISTRICT.y = c("BUTLER CO SCH DIST", 
"BUTLER CO SCH DIST", "BUTLER COUNTY SCHOOL DISTRICT", "BUTLER COUNTY SCHOOL DISTRICT", 
"ANNISTON CTY SCH DST", "CALHOUN CO SCH DIST", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCH DIST", "PIEDMONT CTY SCH DIST", "ANNISTON CTY SCH DST", 
"CALHOUN CO SCH DIST", "JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCH DIST", 
"PIEDMONT CTY SCH DIST", "ANNISTON CTY SCH DST", "CALHOUN COUNTY SCHOOL DISTRICT", 
"JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCHOOL DISTRICT", 
"PIEDMONT CITY SCHOOL DISTRICT", "ANNISTON CITY SCHOOL DISTRICT", 
"CALHOUN COUNTY SCHOOL DISTRICT", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCHOOL DISTRICT", "PIEDMONT CITY SCHOOL DISTRICT", 
"ANNISTON CITY SCHOOL DISTRICT", "CALHOUN COUNTY SCHOOL DISTRICT", 
"JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCHOOL DISTRICT", 
"PIEDMONT CITY SCHOOL DISTRICT", "ANNISTON CITY SCHOOL DISTRICT", 
"CALHOUN COUNTY SCHOOL DISTRICT", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCHOOL DISTRICT", "PIEDMONT CITY SCHOOL DISTRICT", 
"ANNISTON CITY SCHOOL DISTRICT", "CALHOUN COUNTY SCHOOL DISTRICT", 
"JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCHOOL DISTRICT", 
"PIEDMONT CITY SCHOOL DISTRICT", "ANNISTON CITY SCHOOL DISTRICT", 
"CALHOUN COUNTY SCHOOL DISTRICT", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCHOOL DISTRICT", "PIEDMONT CITY SCHOOL DISTRICT", 
"ANNISTON CITY SCHOOL DISTRICT", "CALHOUN COUNTY SCHOOL DISTRICT", 
"JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCHOOL DISTRICT", 
"PIEDMONT CITY SCHOOL DISTRICT", "ANNISTON CITY SCHOOL DISTRICT", 
"CALHOUN COUNTY SCHOOL DISTRICT", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCHOOL DISTRICT", "PIEDMONT CITY SCHOOL DISTRICT", 
"ANNISTON CITY SCHOOL DISTRICT", "CALHOUN COUNTY SCHOOL DISTRICT", 
"JACKSONVILLE CITY SCHOOL DISTRICT", "OXFORD CITY SCHOOL DISTRICT", 
"PIEDMONT CITY SCHOOL DISTRICT", "ANNISTON CITY SCHOOL DISTRICT", 
"CALHOUN COUNTY SCHOOL DISTRICT", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCHOOL DISTRICT", "PIEDMONT CITY SCHOOL DISTRICT", 
"ANNISTON CTY SCH DST", "CALHOUN CO SCH DIST", "JACKSONVILLE CITY SCHOOL DISTRICT", 
"OXFORD CITY SCH DIST"), EXPENDITURE_PER_STUDENT = c(7593, 8334, 
9281, 9147, 8240, 7216, 6822, 7554, 7155, 8758, 8186, 7323, 8380, 
7710, 9070, 8707, 8070, 8853, 8054, 9364, 8212, 7787, 8560, 7760, 
10006, 8264, 7964, 8771, 8442, 10154, 8209, 7955, 8967, 7911, 
10661, 8157, 8096, 9097, 7660, 11480, 8415, 9351, 8829, 8102, 
12057, 8479, 8708, 8965, 8443, 10988, 8930, 8932, 9118, 8706, 
11277, 9134, 9223, 9347, 8524, 11277, 9134, 9223, 9347, 8524, 
8758, 8186, 7323, 8380), PLACE_ID = c("0101345496", "0101345496", 
"0101345496", "0101345496", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101501852", "0101501852", "0101501852", 
"0101501852", "0101501852", "0101529992", "0101529992", "0101529992", 
"0101529992"), CITY = c("mckenzie", "mckenzie", "mckenzie", "mckenzie", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"anniston", "anniston", "anniston", "anniston", "anniston", "anniston", 
"glencoe", "glencoe", "glencoe", "glencoe"), POPULATION.EST = c(548, 
542, 536, 526, 23470, 23470, 23470, 23470, 23470, 23360, 23360, 
23360, 23360, 23360, 23313, 23313, 23313, 23313, 23313, 23262, 
23262, 23262, 23262, 23262, 23106, 23106, 23106, 23106, 23106, 
22849, 22849, 22849, 22849, 22849, 22644, 22644, 22644, 22644, 
22644, 22457, 22457, 22457, 22457, 22457, 22280, 22280, 22280, 
22280, 22280, 22107, 22107, 22107, 22107, 22107, 21926, 21926, 
21926, 21926, 21926, 21770, 21770, 21770, 21770, 21770, 32, 32, 
32, 32), CRIME_VIOLENT = c(1, 0, 2, 1, 521, 521, 521, 521, 521, 
541, 541, 541, 541, 541, 572, 572, 572, 572, 572, 584, 584, 584, 
584, 584, 0, 0, 0, 0, 0, 411, 411, 411, 411, 411, 504, 504, 504, 
504, 504, 461, 461, 461, 461, 461, 536, 536, 536, 536, 536, 607, 
607, 607, 607, 607, 735, 735, 735, 735, 735, 754, 754, 754, 754, 
754, 9, 9, 9, 9), CRIME_PROPERTY = c(6, 9, 9, 7, 3044, 3044, 
3044, 3044, 3044, 2912, 2912, 2912, 2912, 2912, 2429, 2429, 2429, 
2429, 2429, 2379, 2379, 2379, 2379, 2379, 2038, 2038, 2038, 2038, 
2038, 2323, 2323, 2323, 2323, 2323, 2484, 2484, 2484, 2484, 2484, 
1988, 1988, 1988, 1988, 1988, 1711, 1711, 1711, 1711, 1711, 1645, 
1645, 1645, 1645, 1645, 1712, 1712, 1712, 1712, 1712, 1352, 1352, 
1352, 1352, 1352, 106, 106, 106, 106), CRIME_TOTAL = c(7, 9, 
11, 8, 3565, 3565, 3565, 3565, 3565, 3453, 3453, 3453, 3453, 
3453, 3001, 3001, 3001, 3001, 3001, 2963, 2963, 2963, 2963, 2963, 
2038, 2038, 2038, 2038, 2038, 2734, 2734, 2734, 2734, 2734, 2988, 
2988, 2988, 2988, 2988, 2449, 2449, 2449, 2449, 2449, 2247, 2247, 
2247, 2247, 2247, 2252, 2252, 2252, 2252, 2252, 2447, 2447, 2447, 
2447, 2447, 2106, 2106, 2106, 2106, 2106, 115, 115, 115, 115), 
    prop.5.17.pov = c(30.2, 33.1, 28.1, 33.4, 25.6, 25.6, 25.6, 
    25.6, 25.6, 24, 24, 24, 24, 24, 20.1, 20.1, 20.1, 20.1, 20.1, 
    23.7, 23.7, 23.7, 23.7, 23.7, 30.8, 30.8, 30.8, 30.8, 30.8, 
    31.1, 31.1, 31.1, 31.1, 31.1, 30.5, 30.5, 30.5, 30.5, 30.5, 
    27, 27, 27, 27, 27, 25.4, 25.4, 25.4, 25.4, 25.4, 29.8, 29.8, 
    29.8, 29.8, 29.8, 24.2, 24.2, 24.2, 24.2, 24.2, NA, NA, NA, 
    NA, NA, 24, 24, 24, 24)), row.names = c(NA, -68L), class = c("tbl_df", 
"tbl", "data.frame"))

1 个答案:

答案 0 :(得分:0)

一个非常部分的答案:

  • (year|PLACE_ID/COUNTY_ID)向后看(嵌套语法为larger/smaller),但是鉴于您对编码的描述,(year|PLACE_ID) + (year|COUNTY_ID)(year|COUNTY_ID/PLACE_ID)都可以使用。 (或(year|STATE/COUNTY_ID/PLACE_ID)吗?)
  • 跨越地区和州/县似乎很合理,尽管我可以想象,如果某些PLACE_ID构成一个单个学区,事情会变得有些奇怪...
  • 可以按地区分配支出

很难说完整模型出了什么问题。您可以取多小的子样本数据来复制问题?该模型可以用作线性混合模型吗?如果是这样,拟合后的模型是否可以为您提供有关数据/模型可能有何怪异之处的任何提示?