Test discrete optimal allocation solution line by line without function. Use the California student test score dataset. Regress student English and Math test scores on Student-Teacher-Ratio.

Data Structures

The california school dataset, the effect of teacher ratio on student scores. The overall structure is:

  1. Inputs:
    • df_input_il: prefer the input dataframe as specified below
      • \(N \times D\) by \(7\), and \(D\) might be individual specific.
    • \(\rho\): planner inequality aversion, in paper refereed to as \(\rho\).
    • \(\widehat{W}\): resource available
    • \(\mathcal{O}^{o}\): utility at observed allocations
    • Policy Parameters:
      • \(\mathcal{FI}^{\text{max}}\): maximum increase fraction for each \(i\), shared across \(i\), other problems could have more \(i\) specific upper bounds. Here the existing level of teachers per district multiplied by \(\mathcal{F}^{\text{max}}\) provides the maximum increase per district allowed
      • \(\mathcal{FA}^{\text{max}}\): aggregate increase in total resource allowed, total existing teacher count multiplied by this gives \(widehat{W}\).
  2. df_queue_il: compute optimal targeting queue, for many \(\rho\), relies completely on binary allocation function, need to structure data
    • \(N \times D\) by \(8\), + 1 rank
    • in practice, solve concurrently for multiple \(\rho\), leading to wide and long version of the same file.
      • df_queue_il_wide: \(N \times D\) rows with \(L\) addition columns for each \(\rho\) solved for.
      • df_queue_il_long: \(N \times D \times \rho\) rows with \(L\) times additioan rows for each \(\rho\) solved for.
    • Invokes ffp_opt_anlyz_rhgin_bin
    • Using the binary targeting queue function, generate df_queue_il, which introduces an additional \(Q_{il}\) Variable.
    • This is a function of \(\rho\)
  3. df_alloc_i: aggregate to obtain optimal allocations given resource constraint, this is a dplyr aggregation command
    • \(N\) rows, individual allocations
    • This introduceds \(D^{\star}_i\), optimal allocation given resources
    • This is a function of \(\rho\) as well as \(\widehat{W}\)
  4. df_rev_il: rev computation
    • \(N \times \widehat{W}\) rows
    • Invokes ff_panel_cumsum_grouplast
    • This is a function o f\(\mathcal{O}^{o}\) and \(\rho\) (for computing reasons, also \(\widehat{W}\)).
    • compute \(\Delta^{\text{REV}}\), which is a float

In Particular, the input Data Structures are:

The df_input_il frame is based on another dataframe, df_casch_prep_i that generates the variables in df_input_il, and df_opt_caschool which is the raw dataframe:

  • df_opt_caschool: raw dataframe
  • df_casch_prep_i: individual (district) level dataframe
    • includes comparison allocation, in the test here, uniform allocation
  • df_input_il: input frame for optimal allocations
  • df_queue_il_long: optimal targeting queue, wide, \(\rho\) results as rows, this is the main file
    • df_queue_il_wide: optimal targeting queue, wide, \(\rho\) results as columns, this is the support file, because only one value distributed to each \(\rho\). Long version can have multiple \(\rho\) specific values.
  • df_alloc_i_long: aggregate allocations up
  • df_rev_il

The df_casch_prep_i Dataframe

This is not general, in each specific problem, this dataframe could be different.

  1. \(\text{ID}_i\): individual id
  2. \(D^{\text{max}}_{i}\): maximimum discrete allocation each person, in addition to existing levels
  3. \(D^{\text{o}}_{i}\): what I call observed allocation, just any comparison allocation, in addition to existing levels, this is the additional allocation (ignoring existing levels), this is the not the total allocation. If fully redistributing, this could be the observed level of allocation.
  4. \(\Omega_{i}\): This is the expected outcome when the input of interest is completely zero, \(Omega_{i}\neq A_{i,l=0}\), because \(l=0\) does not mean input is zero, using \(\Omega_i\) rather than \(A_i\) to avoid confusion because \(A_i\) sounds like \(A_i = A_{i, l=0}\), but again, the problem does not start with allocation at zero, but each district already has some existing number of teachers.
  5. \(\theta_{i}\): coefficient in front of student teacher ratio
  6. \(\beta_{i}\): i specific preference
  7. \(\text{enrltot}_{i}\): enrollment per district/school, assume no within district variations
  8. \(\text{teachers}_{i}\): teacher per distrct/school
  9. \(\text{stravg}_{i}\): average of student teacher ratio district/school

The df_input_il Dataframe

The df_input_il Dataframe has:

  1. \(\text{ID}_i\): individual id
  2. \(\text{ID}_{il}\): unique id for individual/allocation id
  3. \(D^{\text{max}}_{i}\): maximimum discrete allocation each person
  4. \(D_{il}\): lth discrete allocation level for ith person, if fully redistributing, then this is equal to toal allocation count, if this is distribution additional teachers, this is equal to the additional allocation of teachers for each school.
  5. \(A_{il}\): A when considering the lth allocation for ith person, expected outcome without the lth allocation
  6. \(\alpha_{il}\): marginal expected effect of the lth allocation
  7. \(\beta_{i}\): i specific preference

The df_input_ib Dataframe is what would be generated for binary allocation in some sense:

  1. \(\text{ID}_i\): individual id
  2. \(A_{i,l=0}\): A when considering the lth allocation for ith person, expected outcome without the lth allocation
  3. \(\alpha^{\text{o}}_{i}\): see df_casch_prep_i, observed/random/uniform allocation’s marginal effect. Note since \(\alpha_{il}\) considers only additional allocation, with existing allocations embeded in \(D_{il}\), \(\alpha^{\text{o}}_{i}\) also only includes additional allocations that is not already embeded in \(\A_{i,l=0}\).
  4. \(\beta_{i}\): i specific preference

The df_queue_il Dataframe

For df_queue_il_long, same as df_input_il, but add:

  1. \(\text{IDX}_{\rho}\): index for rho
  2. \(\rho\): actual rho values
  3. \(Q_{il}\): allocation rank for the lth discrete allocation level for ith person.
  4. \(D^{\widehat{W},\text{BIN}}_{il}\): \(0\) or \(1\), given \(\widehat{W}\), whether individual \(i^{th}\) \(l^{th}\) allocation is allocated.
  5. \(V^{Q}_{il}\): V_star_Q_il value given optimal choices at queue point

For df_queue_il_wide, same as df_input_il, but add:

  1. Add teachers, enrltot, and theta_i

The df_value_il Dataframe

This is the optimal allocation dataframe where each row is a queue rank, and each column is an individual. Each cell stores at this allocation queue rank, how many units have been allocated to individual i. This is a cumulative sum result. Obtained by calling REconTool’s function ff_panel_expand_longrosterwide.

  1. \(\rho\)
  2. \(\text{Q}\): Current Queue index
  3. \(D^{\star, \widehat{W}=Q}_{i}\): separate columns for each \(i\) optimal allocation for \(i^{th}\) person,when \(\widehat{W}=Q\)

This if generated, would be merged into df_queue_il_long afterwards. But df_queue_il does not necessarily need to generate this.

Optionally, can generate this for all Q_il points, or only at Queue ranks where \(D^{\widehat{W},\text{BIN}}_{il} = 1\).

The df_alloc_i Dataframe

df_alloc_i_long based on aggregating allocations to i level from df_queue_il_long.

  1. \(\text{IDX}_{\rho}\): index for rho
  2. \(\rho\): actual rho values
  3. \(\text{ID}_i\): individual id
  4. \(D^{\text{max}}_{i}\): maximimum discrete allocation each person
  5. \(D^{\star, \widehat{W}}_{i}\): optimal allocation for \(i^{th}\) person, given \(\widehat{W}\)
  6. \(F^{\star, \widehat{W}}_{i}\): \(\frac{D^{\star, \widehat{W}}_{i}}{D^{\text{max}}_{i}}\)
  7. \(EH^{\star, \widehat{Q}}_{i}\): expected outcome given optimal allocations/choices

The mt_rev Dataframe

REV matrix where each element is for a differen trho.

  1. \(\text{IDX}_{\rho}\): index for rho
  2. \(\rho\): actual rho values
  3. \(\Delta^{\text{REV}}\): resource equivalent variation at each \(\rho\) value.

Set-Up

Load Dependencies

rm(list = ls(all.names = TRUE))
options(knitr.duplicate.label = 'allow')

Policy Parameters

Some parameters that can be determined regardless of actual data. Note that we will define inputs needed to generate df_queue_il, df_alloc_i and df_rev_il after df_input_il is prepared.

# 100 percent teacher at most per school, discretize floor as needed
fl_fi_max = 1.00
# 20 percent total additional of all teachers
fl_fa_max = 0.20
# Rho values to consider
# ar_rho = c(-100, -0.001,  0.95)
ar_rho <- 1 - (10^(c(seq(-2,2, length.out=4))))
ar_rho <- unique(ar_rho)

Load Data

Generate four categories by initial height and mother’s education levels combinations. Note the dataset does not provide all the details we want, so we will make some assumptions. Importantly, we only have averages within district.

  1. teachers: is full-time-equivalent average number of teacher per district.
  2. enrl_tot: is the enrollment average per district
# Load Data
data(df_opt_caschool)
dfca <- df_opt_caschool

# Summarize
str(dfca)
## 'data.frame':    420 obs. of  18 variables:
##  $ X       : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ distcod : int  75119 61499 61549 61457 61523 62042 68536 63834 62331 67306 ...
##  $ county  : Factor w/ 45 levels "Alameda","Butte",..: 1 2 2 2 2 6 29 11 6 25 ...
##  $ district: Factor w/ 409 levels "Ackerman Elementary",..: 362 214 367 134 270 53 152 383 263 93 ...
##  $ grspan  : Factor w/ 2 levels "KK-06","KK-08": 2 2 2 2 2 2 2 2 2 1 ...
##  $ enrltot : int  195 240 1550 243 1335 137 195 888 379 2247 ...
##  $ teachers: num  10.9 11.1 82.9 14 71.5 ...
##  $ calwpct : num  0.51 15.42 55.03 36.48 33.11 ...
##  $ mealpct : num  2.04 47.92 76.32 77.05 78.43 ...
##  $ computer: int  67 101 169 85 171 25 28 66 35 0 ...
##  $ testscr : num  691 661 644 648 641 ...
##  $ compstu : num  0.344 0.421 0.109 0.35 0.128 ...
##  $ expnstu : num  6385 5099 5502 7102 5236 ...
##  $ str     : num  17.9 21.5 18.7 17.4 18.7 ...
##  $ avginc  : num  22.69 9.82 8.98 8.98 9.08 ...
##  $ elpct   : num  0 4.58 30 0 13.86 ...
##  $ readscr : num  692 660 636 652 642 ...
##  $ mathscr : num  690 662 651 644 640 ...
summary(dfca)
##        X            distcod              county   
##  Min.   :  1.0   Min.   :61382   Sonoma     : 29  
##  1st Qu.:105.8   1st Qu.:64308   Kern       : 27  
##  Median :210.5   Median :67761   Los Angeles: 27  
##  Mean   :210.5   Mean   :67473   Tulare     : 24  
##  3rd Qu.:315.2   3rd Qu.:70419   San Diego  : 21  
##  Max.   :420.0   Max.   :75440   Santa Clara: 20  
##                                  (Other)    :272  
##                       district     grspan       enrltot       
##  Lakeside Union Elementary:  3   KK-06: 61   Min.   :   81.0  
##  Mountain View Elementary :  3   KK-08:359   1st Qu.:  379.0  
##  Jefferson Elementary     :  2               Median :  950.5  
##  Liberty Elementary       :  2               Mean   : 2628.8  
##  Ocean View Elementary    :  2               3rd Qu.: 3008.0  
##  Pacific Union Elementary :  2               Max.   :27176.0  
##  (Other)                  :406                                
##     teachers          calwpct          mealpct          computer     
##  Min.   :   4.85   Min.   : 0.000   Min.   :  0.00   Min.   :   0.0  
##  1st Qu.:  19.66   1st Qu.: 4.395   1st Qu.: 23.28   1st Qu.:  46.0  
##  Median :  48.56   Median :10.520   Median : 41.75   Median : 117.5  
##  Mean   : 129.07   Mean   :13.246   Mean   : 44.71   Mean   : 303.4  
##  3rd Qu.: 146.35   3rd Qu.:18.981   3rd Qu.: 66.86   3rd Qu.: 375.2  
##  Max.   :1429.00   Max.   :78.994   Max.   :100.00   Max.   :3324.0  
##                                                                      
##     testscr         compstu           expnstu          str       
##  Min.   :605.5   Min.   :0.00000   Min.   :3926   Min.   :14.00  
##  1st Qu.:640.0   1st Qu.:0.09377   1st Qu.:4906   1st Qu.:18.58  
##  Median :654.5   Median :0.12546   Median :5215   Median :19.72  
##  Mean   :654.2   Mean   :0.13593   Mean   :5312   Mean   :19.64  
##  3rd Qu.:666.7   3rd Qu.:0.16447   3rd Qu.:5601   3rd Qu.:20.87  
##  Max.   :706.8   Max.   :0.42083   Max.   :7712   Max.   :25.80  
##                                                                  
##      avginc           elpct           readscr         mathscr     
##  Min.   : 5.335   Min.   : 0.000   Min.   :604.5   Min.   :605.4  
##  1st Qu.:10.639   1st Qu.: 1.941   1st Qu.:640.4   1st Qu.:639.4  
##  Median :13.728   Median : 8.778   Median :655.8   Median :652.5  
##  Mean   :15.317   Mean   :15.768   Mean   :655.0   Mean   :653.3  
##  3rd Qu.:17.629   3rd Qu.:22.970   3rd Qu.:668.7   3rd Qu.:665.9  
##  Max.   :55.328   Max.   :85.540   Max.   :704.0   Max.   :709.5  
## 
dfca %>% group_by(county) %>%
  summarise_if(is.numeric, funs(mean = mean), na.rm = TRUE)
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
## # A tibble: 45 x 16
##    county       X_mean distcod_mean enrltot_mean teachers_mean calwpct_mean
##    <fct>         <dbl>        <dbl>        <dbl>         <dbl>        <dbl>
##  1 Alameda          1        75119          195          10.9         0.510
##  2 Butte           36        61486.        1152.         60.5        36.3  
##  3 Calaveras      233        61572          777          36.8        13.0  
##  4 Contra Costa   299.       61738.        2726.        138.          3.51 
##  5 El Dorado      294.       61912.        1373.         69.5         6.73 
##  6 Fresno         111        62250.         504.         26.4        21.1  
##  7 Glenn          264.       62596          138.          6.58        7.11 
##  8 Humboldt       240.       62888.         380.         20.6        17.8  
##  9 Imperial       121.       63163.        1936          92.5        19.7  
## 10 Inyo           252        63255         1510          73.3        10.3  
## # ... with 35 more rows, and 10 more variables: mealpct_mean <dbl>,
## #   computer_mean <dbl>, testscr_mean <dbl>, compstu_mean <dbl>,
## #   expnstu_mean <dbl>, str_mean <dbl>, avginc_mean <dbl>, elpct_mean <dbl>,
## #   readscr_mean <dbl>, mathscr_mean <dbl>
# Modifying and labeling etc.
# School characteristics are averaged across the district, don't know school count per district, implicitly assume the number of schools per district is the same.
# Some districts have larger and others smaller sized schools, ignoring within district variations.
dfca <- dfca %>%
          mutate(id_i = X) %>% select(-X) %>%
          select(id_i, everything()) %>%
          mutate(teachers = round(teachers),
                 enrltot = round(enrltot))

# Student and Teacher Ratio, str and stravg are almost identical
# use stravg because need to use enrltot and teachers variables later
dfca <- dfca %>% mutate(stravg = enrltot/teachers)
# view(dfca %>% select(stravg, str))

# Generate Discrete Version of continuous variables
# df_opt_birthwt <- df_opt_birthwt %>%
#     mutate(momwgtLowHigh = cut(lwt,
#                                breaks=c(-Inf, 129, Inf),
#                                labels=c("LW","HW"))) %>%
#     mutate(mombirthage = cut(age,
#                                breaks=c(-Inf, 24, Inf),
#                                labels=c("young","older"))) %>%
#     mutate(ftvm3 = cut(ftv,
#                                breaks=c(-Inf, 1, 2, Inf),
#                                labels=c("novisit","1visit","morevisit")))

DF1: Effect of Teacher on Scores (df_casch_prep_i)

The objective of this section is the generate dataframe df_casch_prep_i.

Tabulate

# Tabulate groups, how many in each group, enough for group heterogeneity in effects?
dfca %>%
  group_by(county, grspan) %>%
  summarize(freq = n()) %>%
  pivot_wider(names_from = grspan, values_from = freq)
## `summarise()` has grouped output by 'county'. You can override using the `.groups` argument.
## # A tibble: 45 x 3
## # Groups:   county [45]
##    county       `KK-08` `KK-06`
##    <fct>          <int>   <int>
##  1 Alameda            1      NA
##  2 Butte              6      NA
##  3 Calaveras          1      NA
##  4 Contra Costa       7      NA
##  5 El Dorado         10      NA
##  6 Fresno            12      NA
##  7 Glenn              3      NA
##  8 Humboldt          14       3
##  9 Imperial           6      NA
## 10 Inyo               1      NA
## # ... with 35 more rows

Regression Testing

The allocation policy is in terms of teachers. How many teachers to add. Given the current number of teachers in the school, suppose there is some capacity limit at each school, so the number of additional teachers at each school can not exceed 35 percent of the teachers that are already there.

Our estimation is based on regressing thest score on the student teacher ratio, from which we obtain a single estimate \(\alpha\).

\[ Y_i = A_i + \theta \cdot \frac{S_i}{T_i} + \epsilon \]

What is the marginal effect of adding one more unit?

What is the effect of adding an additional teacher?

We need to translate the estimate \(\theta\) here into our equation’s allocation scale

\[ Y_i \left(T_i\right) = A_i + \theta \cdot \frac{S_i}{T_i} + \epsilon\\ Y_i \left(T_i + 1\right) = A_i + \theta \cdot \frac{S_i}{T_i + 1} + \epsilon\\ EY_i \left(T_i + 1\right) - EY_i \left(T_i\right) = \theta \cdot S_i \cdot \left( \frac{1}{T_i + 1} - \frac{1}{T_i} \right) \]

attach(dfca)

# Math, English, and Overall and str = student teacher ratio
summary(lm(mathscr ~ str))
## 
## Call:
## lm(formula = mathscr ~ str)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -44.615 -13.374  -0.828  12.728  52.711 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 691.4174     9.3825  73.692  < 2e-16 ***
## str          -1.9386     0.4755  -4.077 5.47e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.41 on 418 degrees of freedom
## Multiple R-squared:  0.03824,    Adjusted R-squared:  0.03594 
## F-statistic: 16.62 on 1 and 418 DF,  p-value: 5.467e-05
summary(lm(readscr ~ str))
## 
## Call:
## lm(formula = readscr ~ str)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -50.839 -14.479   1.121  14.495  44.370 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 706.4485     9.9410  71.064  < 2e-16 ***
## str          -2.6210     0.5038  -5.202 3.09e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 19.51 on 418 degrees of freedom
## Multiple R-squared:  0.06081,    Adjusted R-squared:  0.05856 
## F-statistic: 27.06 on 1 and 418 DF,  p-value: 3.091e-07
summary(lm(testscr ~ str))
## 
## Call:
## lm(formula = testscr ~ str)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -47.727 -14.251   0.483  12.822  48.540 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 698.9330     9.4675  73.825  < 2e-16 ***
## str          -2.2798     0.4798  -4.751 2.78e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.58 on 418 degrees of freedom
## Multiple R-squared:  0.05124,    Adjusted R-squared:  0.04897 
## F-statistic: 22.58 on 1 and 418 DF,  p-value: 2.783e-06
summary(lm(testscr ~ stravg))
## 
## Call:
## lm(formula = testscr ~ stravg)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -47.719 -14.504   0.435  12.510  48.536 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 700.2132     9.3732  74.704  < 2e-16 ***
## stravg       -2.3458     0.4752  -4.937 1.15e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.54 on 418 degrees of freedom
## Multiple R-squared:  0.05509,    Adjusted R-squared:  0.05283 
## F-statistic: 24.37 on 1 and 418 DF,  p-value: 1.15e-06
# Regress test score on str with student and teacher counts
summary(lm(testscr ~ enrltot + teachers + str))
## 
## Call:
## lm(formula = testscr ~ enrltot + teachers + str)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -48.726 -13.723   0.454  12.646  48.613 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 691.053506  11.009245  62.770  < 2e-16 ***
## enrltot      -0.002793   0.003459  -0.808  0.41981    
## teachers      0.048168   0.071289   0.676  0.49962    
## str          -1.821241   0.563315  -3.233  0.00132 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.53 on 416 degrees of freedom
## Multiple R-squared:  0.06047,    Adjusted R-squared:  0.0537 
## F-statistic: 8.925 on 3 and 416 DF,  p-value: 9.632e-06
summary(lm(testscr ~ enrltot + teachers + stravg))
## 
## Call:
## lm(formula = testscr ~ enrltot + teachers + stravg)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -48.699 -13.748   0.399  12.380  48.667 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 692.964476  10.889054  63.639  < 2e-16 ***
## enrltot      -0.002493   0.003448  -0.723 0.470167    
## teachers      0.042248   0.071067   0.594 0.552508    
## stravg       -1.920592   0.557423  -3.445 0.000628 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.5 on 416 degrees of freedom
## Multiple R-squared:  0.06359,    Adjusted R-squared:  0.05683 
## F-statistic: 9.416 on 3 and 416 DF,  p-value: 4.942e-06
# Regress test score on str with covariates and county fe
summary(lm(testscr ~ factor(county) + calwpct + mealpct + computer + str - 1))
## 
## Call:
## lm(formula = testscr ~ factor(county) + calwpct + mealpct + computer + 
##     str - 1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -32.035  -4.981   0.188   5.137  23.819 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## factor(county)Alameda          7.072e+02  1.001e+01  70.621  < 2e-16 ***
## factor(county)Butte            7.009e+02  6.696e+00 104.678  < 2e-16 ***
## factor(county)Calaveras        6.980e+02  1.053e+01  66.301  < 2e-16 ***
## factor(county)Contra Costa     6.980e+02  6.391e+00 109.215  < 2e-16 ***
## factor(county)El Dorado        6.947e+02  6.152e+00 112.916  < 2e-16 ***
## factor(county)Fresno           6.959e+02  6.102e+00 114.043  < 2e-16 ***
## factor(county)Glenn            7.068e+02  7.953e+00  88.870  < 2e-16 ***
## factor(county)Humboldt         6.991e+02  5.687e+00 122.930  < 2e-16 ***
## factor(county)Imperial         6.960e+02  7.079e+00  98.314  < 2e-16 ***
## factor(county)Inyo             6.987e+02  1.044e+01  66.892  < 2e-16 ***
## factor(county)Kern             6.940e+02  6.010e+00 115.462  < 2e-16 ***
## factor(county)Kings            6.972e+02  6.456e+00 107.997  < 2e-16 ***
## factor(county)Lake             6.988e+02  8.372e+00  83.464  < 2e-16 ***
## factor(county)Lassen           6.988e+02  7.163e+00  97.556  < 2e-16 ***
## factor(county)Los Angeles      6.959e+02  6.328e+00 109.969  < 2e-16 ***
## factor(county)Madera           6.994e+02  6.788e+00 103.030  < 2e-16 ***
## factor(county)Marin            7.014e+02  5.893e+00 119.016  < 2e-16 ***
## factor(county)Mendocino        6.918e+02  1.047e+01  66.085  < 2e-16 ***
## factor(county)Merced           6.946e+02  6.380e+00 108.866  < 2e-16 ***
## factor(county)Monterey         6.887e+02  6.811e+00 101.116  < 2e-16 ***
## factor(county)Nevada           6.972e+02  6.024e+00 115.734  < 2e-16 ***
## factor(county)Orange           6.981e+02  6.579e+00 106.109  < 2e-16 ***
## factor(county)Placer           6.976e+02  6.325e+00 110.301  < 2e-16 ***
## factor(county)Riverside        6.946e+02  7.444e+00  93.310  < 2e-16 ***
## factor(county)Sacramento       6.900e+02  6.599e+00 104.565  < 2e-16 ***
## factor(county)San Benito       6.821e+02  7.252e+00  94.066  < 2e-16 ***
## factor(county)San Bernardino   6.935e+02  6.573e+00 105.507  < 2e-16 ***
## factor(county)San Diego        7.010e+02  5.944e+00 117.924  < 2e-16 ***
## factor(county)San Joaquin      6.852e+02  6.611e+00 103.656  < 2e-16 ***
## factor(county)San Luis Obispo  6.982e+02  8.217e+00  84.980  < 2e-16 ***
## factor(county)San Mateo        6.969e+02  5.594e+00 124.580  < 2e-16 ***
## factor(county)Santa Barbara    7.014e+02  6.219e+00 112.776  < 2e-16 ***
## factor(county)Santa Clara      6.990e+02  5.947e+00 117.544  < 2e-16 ***
## factor(county)Santa Cruz       7.032e+02  6.407e+00 109.764  < 2e-16 ***
## factor(county)Shasta           7.008e+02  6.059e+00 115.659  < 2e-16 ***
## factor(county)Siskiyou         6.988e+02  5.461e+00 127.960  < 2e-16 ***
## factor(county)Sonoma           6.967e+02  5.513e+00 126.365  < 2e-16 ***
## factor(county)Stanislaus       6.933e+02  6.582e+00 105.325  < 2e-16 ***
## factor(county)Sutter           6.853e+02  6.840e+00 100.200  < 2e-16 ***
## factor(county)Tehama           7.018e+02  6.427e+00 109.189  < 2e-16 ***
## factor(county)Trinity          7.259e+02  8.093e+00  89.691  < 2e-16 ***
## factor(county)Tulare           6.969e+02  6.260e+00 111.321  < 2e-16 ***
## factor(county)Tuolumne         6.970e+02  6.274e+00 111.095  < 2e-16 ***
## factor(county)Ventura          6.955e+02  6.811e+00 102.113  < 2e-16 ***
## factor(county)Yuba             7.121e+02  8.325e+00  85.532  < 2e-16 ***
## calwpct                        1.591e-02  6.949e-02   0.229  0.81898    
## mealpct                       -5.909e-01  2.833e-02 -20.861  < 2e-16 ***
## computer                      -1.145e-04  1.172e-03  -0.098  0.92227    
## str                           -8.483e-01  2.853e-01  -2.973  0.00314 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.621 on 371 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 4.938e+04 on 49 and 371 DF,  p-value: < 2.2e-16
summary(lm(testscr ~ factor(county) + calwpct + mealpct + computer + stravg - 1))
## 
## Call:
## lm(formula = testscr ~ factor(county) + calwpct + mealpct + computer + 
##     stravg - 1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -32.983  -4.907   0.122   4.895  23.816 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## factor(county)Alameda          7.074e+02  9.929e+00  71.249  < 2e-16 ***
## factor(county)Butte            7.013e+02  6.598e+00 106.285  < 2e-16 ***
## factor(county)Calaveras        6.984e+02  1.043e+01  66.943  < 2e-16 ***
## factor(county)Contra Costa     6.985e+02  6.297e+00 110.919  < 2e-16 ***
## factor(county)El Dorado        6.951e+02  6.053e+00 114.842  < 2e-16 ***
## factor(county)Fresno           6.965e+02  6.051e+00 115.100  < 2e-16 ***
## factor(county)Glenn            7.070e+02  7.793e+00  90.720  < 2e-16 ***
## factor(county)Humboldt         6.994e+02  5.572e+00 125.533  < 2e-16 ***
## factor(county)Imperial         6.965e+02  6.999e+00  99.518  < 2e-16 ***
## factor(county)Inyo             6.992e+02  1.038e+01  67.367  < 2e-16 ***
## factor(county)Kern             6.943e+02  5.882e+00 118.041  < 2e-16 ***
## factor(county)Kings            6.975e+02  6.324e+00 110.302  < 2e-16 ***
## factor(county)Lake             6.992e+02  8.305e+00  84.190  < 2e-16 ***
## factor(county)Lassen           6.992e+02  7.034e+00  99.402  < 2e-16 ***
## factor(county)Los Angeles      6.963e+02  6.201e+00 112.288  < 2e-16 ***
## factor(county)Madera           6.998e+02  6.695e+00 104.536  < 2e-16 ***
## factor(county)Marin            7.018e+02  5.803e+00 120.925  < 2e-16 ***
## factor(county)Mendocino        6.917e+02  1.031e+01  67.113  < 2e-16 ***
## factor(county)Merced           6.949e+02  6.250e+00 111.181  < 2e-16 ***
## factor(county)Monterey         6.891e+02  6.692e+00 102.973  < 2e-16 ***
## factor(county)Nevada           6.976e+02  5.923e+00 117.772  < 2e-16 ***
## factor(county)Orange           6.986e+02  6.457e+00 108.180  < 2e-16 ***
## factor(county)Placer           6.979e+02  6.178e+00 112.971  < 2e-16 ***
## factor(county)Riverside        6.950e+02  7.334e+00  94.766  < 2e-16 ***
## factor(county)Sacramento       6.904e+02  6.494e+00 106.314  < 2e-16 ***
## factor(county)San Benito       6.826e+02  7.182e+00  95.036  < 2e-16 ***
## factor(county)San Bernardino   6.939e+02  6.460e+00 107.421  < 2e-16 ***
## factor(county)San Diego        7.013e+02  5.823e+00 120.452  < 2e-16 ***
## factor(county)San Joaquin      6.855e+02  6.463e+00 106.062  < 2e-16 ***
## factor(county)San Luis Obispo  6.991e+02  8.235e+00  84.899  < 2e-16 ***
## factor(county)San Mateo        6.973e+02  5.492e+00 126.978  < 2e-16 ***
## factor(county)Santa Barbara    7.018e+02  6.105e+00 114.962  < 2e-16 ***
## factor(county)Santa Clara      6.994e+02  5.836e+00 119.849  < 2e-16 ***
## factor(county)Santa Cruz       7.034e+02  6.245e+00 112.635  < 2e-16 ***
## factor(county)Shasta           7.013e+02  5.998e+00 116.934  < 2e-16 ***
## factor(county)Siskiyou         6.991e+02  5.391e+00 129.679  < 2e-16 ***
## factor(county)Sonoma           6.970e+02  5.396e+00 129.168  < 2e-16 ***
## factor(county)Stanislaus       6.936e+02  6.446e+00 107.601  < 2e-16 ***
## factor(county)Sutter           6.856e+02  6.694e+00 102.430  < 2e-16 ***
## factor(county)Tehama           7.021e+02  6.297e+00 111.491  < 2e-16 ***
## factor(county)Trinity          7.265e+02  8.067e+00  90.061  < 2e-16 ***
## factor(county)Tulare           6.973e+02  6.128e+00 113.781  < 2e-16 ***
## factor(county)Tuolumne         6.974e+02  6.179e+00 112.866  < 2e-16 ***
## factor(county)Ventura          6.958e+02  6.678e+00 104.196  < 2e-16 ***
## factor(county)Yuba             7.125e+02  8.245e+00  86.421  < 2e-16 ***
## calwpct                        1.543e-02  6.941e-02   0.222  0.82425    
## mealpct                       -5.902e-01  2.830e-02 -20.857  < 2e-16 ***
## computer                      -9.125e-05  1.171e-03  -0.078  0.93794    
## stravg                        -8.700e-01  2.794e-01  -3.114  0.00199 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.611 on 371 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 4.95e+04 on 49 and 371 DF,  p-value: < 2.2e-16

Discrete Regression

Need to convert regression results to increment effect.

# Store Regression Results
mt_model <- model.matrix( ~ factor(county) + calwpct + mealpct + computer + stravg)
rs_scr_on_str = lm(testscr ~ mt_model - 1)
print(summary(rs_scr_on_str))
## 
## Call:
## lm(formula = testscr ~ mt_model - 1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -32.983  -4.907   0.122   4.895  23.816 
## 
## Coefficients:
##                                         Estimate Std. Error t value Pr(>|t|)
## mt_model(Intercept)                    7.074e+02  9.929e+00  71.249  < 2e-16
## mt_modelfactor(county)Butte           -6.114e+00  9.475e+00  -0.645  0.51914
## mt_modelfactor(county)Calaveras       -9.023e+00  1.224e+01  -0.737  0.46134
## mt_modelfactor(county)Contra Costa    -8.961e+00  9.225e+00  -0.971  0.33196
## mt_modelfactor(county)El Dorado       -1.231e+01  9.053e+00  -1.360  0.17461
## mt_modelfactor(county)Fresno          -1.094e+01  9.092e+00  -1.204  0.22950
## mt_modelfactor(county)Glenn           -4.135e-01  1.004e+01  -0.041  0.96717
## mt_modelfactor(county)Humboldt        -7.976e+00  8.912e+00  -0.895  0.37136
## mt_modelfactor(county)Imperial        -1.090e+01  9.435e+00  -1.156  0.24852
## mt_modelfactor(county)Inyo            -8.272e+00  1.223e+01  -0.677  0.49904
## mt_modelfactor(county)Kern            -1.308e+01  8.877e+00  -1.473  0.14159
## mt_modelfactor(county)Kings           -9.885e+00  9.159e+00  -1.079  0.28117
## mt_modelfactor(county)Lake            -8.203e+00  1.076e+01  -0.762  0.44647
## mt_modelfactor(county)Lassen          -8.230e+00  9.500e+00  -0.866  0.38688
## mt_modelfactor(county)Los Angeles     -1.113e+01  8.889e+00  -1.253  0.21112
## mt_modelfactor(county)Madera          -7.587e+00  9.494e+00  -0.799  0.42472
## mt_modelfactor(county)Marin           -5.658e+00  9.137e+00  -0.619  0.53610
## mt_modelfactor(county)Mendocino       -1.571e+01  1.225e+01  -1.282  0.20058
## mt_modelfactor(county)Merced          -1.251e+01  9.119e+00  -1.372  0.17094
## mt_modelfactor(county)Monterey        -1.832e+01  9.310e+00  -1.968  0.04986
## mt_modelfactor(county)Nevada          -9.845e+00  9.093e+00  -1.083  0.27967
## mt_modelfactor(county)Orange          -8.874e+00  9.109e+00  -0.974  0.33057
## mt_modelfactor(county)Placer          -9.481e+00  9.029e+00  -1.050  0.29437
## mt_modelfactor(county)Riverside       -1.238e+01  9.744e+00  -1.270  0.20484
## mt_modelfactor(county)Sacramento      -1.701e+01  9.395e+00  -1.810  0.07103
## mt_modelfactor(county)San Benito      -2.485e+01  9.961e+00  -2.494  0.01306
## mt_modelfactor(county)San Bernardino  -1.352e+01  9.127e+00  -1.482  0.13926
## mt_modelfactor(county)San Diego       -6.090e+00  8.885e+00  -0.685  0.49348
## mt_modelfactor(county)San Joaquin     -2.195e+01  9.351e+00  -2.347  0.01943
## mt_modelfactor(county)San Luis Obispo -8.300e+00  1.058e+01  -0.785  0.43324
## mt_modelfactor(county)San Mateo       -1.011e+01  8.881e+00  -1.138  0.25583
## mt_modelfactor(county)Santa Barbara   -5.623e+00  9.037e+00  -0.622  0.53415
## mt_modelfactor(county)Santa Clara     -7.979e+00  8.888e+00  -0.898  0.36993
## mt_modelfactor(county)Santa Cruz      -4.004e+00  9.225e+00  -0.434  0.66452
## mt_modelfactor(county)Shasta          -6.105e+00  9.015e+00  -0.677  0.49869
## mt_modelfactor(county)Siskiyou        -8.289e+00  9.169e+00  -0.904  0.36653
## mt_modelfactor(county)Sonoma          -1.041e+01  8.776e+00  -1.186  0.23636
## mt_modelfactor(county)Stanislaus      -1.386e+01  9.251e+00  -1.498  0.13489
## mt_modelfactor(county)Sutter          -2.181e+01  9.348e+00  -2.333  0.02020
## mt_modelfactor(county)Tehama          -5.347e+00  9.208e+00  -0.581  0.56177
## mt_modelfactor(county)Trinity          1.907e+01  1.061e+01   1.798  0.07306
## mt_modelfactor(county)Tulare          -1.014e+01  8.928e+00  -1.136  0.25659
## mt_modelfactor(county)Tuolumne        -1.004e+01  9.345e+00  -1.074  0.28339
## mt_modelfactor(county)Ventura         -1.158e+01  9.212e+00  -1.257  0.20941
## mt_modelfactor(county)Yuba             5.093e+00  1.062e+01   0.480  0.63170
## mt_modelcalwpct                        1.543e-02  6.941e-02   0.222  0.82425
## mt_modelmealpct                       -5.902e-01  2.830e-02 -20.857  < 2e-16
## mt_modelcomputer                      -9.125e-05  1.171e-03  -0.078  0.93794
## mt_modelstravg                        -8.700e-01  2.794e-01  -3.114  0.00199
##                                          
## mt_model(Intercept)                   ***
## mt_modelfactor(county)Butte              
## mt_modelfactor(county)Calaveras          
## mt_modelfactor(county)Contra Costa       
## mt_modelfactor(county)El Dorado          
## mt_modelfactor(county)Fresno             
## mt_modelfactor(county)Glenn              
## mt_modelfactor(county)Humboldt           
## mt_modelfactor(county)Imperial           
## mt_modelfactor(county)Inyo               
## mt_modelfactor(county)Kern               
## mt_modelfactor(county)Kings              
## mt_modelfactor(county)Lake               
## mt_modelfactor(county)Lassen             
## mt_modelfactor(county)Los Angeles        
## mt_modelfactor(county)Madera             
## mt_modelfactor(county)Marin              
## mt_modelfactor(county)Mendocino          
## mt_modelfactor(county)Merced             
## mt_modelfactor(county)Monterey        *  
## mt_modelfactor(county)Nevada             
## mt_modelfactor(county)Orange             
## mt_modelfactor(county)Placer             
## mt_modelfactor(county)Riverside          
## mt_modelfactor(county)Sacramento      .  
## mt_modelfactor(county)San Benito      *  
## mt_modelfactor(county)San Bernardino     
## mt_modelfactor(county)San Diego          
## mt_modelfactor(county)San Joaquin     *  
## mt_modelfactor(county)San Luis Obispo    
## mt_modelfactor(county)San Mateo          
## mt_modelfactor(county)Santa Barbara      
## mt_modelfactor(county)Santa Clara        
## mt_modelfactor(county)Santa Cruz         
## mt_modelfactor(county)Shasta             
## mt_modelfactor(county)Siskiyou           
## mt_modelfactor(county)Sonoma             
## mt_modelfactor(county)Stanislaus         
## mt_modelfactor(county)Sutter          *  
## mt_modelfactor(county)Tehama             
## mt_modelfactor(county)Trinity         .  
## mt_modelfactor(county)Tulare             
## mt_modelfactor(county)Tuolumne           
## mt_modelfactor(county)Ventura            
## mt_modelfactor(county)Yuba               
## mt_modelcalwpct                          
## mt_modelmealpct                       ***
## mt_modelcomputer                         
## mt_modelstravg                        ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.611 on 371 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 4.95e+04 on 49 and 371 DF,  p-value: < 2.2e-16
rs_scr_on_str_tidy = tidy(rs_scr_on_str)
rs_scr_on_str_tidy
## # A tibble: 49 x 5
##    term                               estimate std.error statistic   p.value
##    <chr>                                 <dbl>     <dbl>     <dbl>     <dbl>
##  1 mt_model(Intercept)                 707.         9.93   71.2    1.54e-218
##  2 mt_modelfactor(county)Butte          -6.11       9.48   -0.645  5.19e-  1
##  3 mt_modelfactor(county)Calaveras      -9.02      12.2    -0.737  4.61e-  1
##  4 mt_modelfactor(county)Contra Costa   -8.96       9.22   -0.971  3.32e-  1
##  5 mt_modelfactor(county)El Dorado     -12.3        9.05   -1.36   1.75e-  1
##  6 mt_modelfactor(county)Fresno        -10.9        9.09   -1.20   2.29e-  1
##  7 mt_modelfactor(county)Glenn          -0.414     10.0    -0.0412 9.67e-  1
##  8 mt_modelfactor(county)Humboldt       -7.98       8.91   -0.895  3.71e-  1
##  9 mt_modelfactor(county)Imperial      -10.9        9.44   -1.16   2.49e-  1
## 10 mt_modelfactor(county)Inyo           -8.27      12.2    -0.677  4.99e-  1
## # ... with 39 more rows

Construct Input Arrays \(A_i\)

Multiply coefficient vector by covariate matrix to generate A vector that is child/individual specific.

# Estimates Table
head(rs_scr_on_str_tidy, 6)
## # A tibble: 6 x 5
##   term                               estimate std.error statistic   p.value
##   <chr>                                 <dbl>     <dbl>     <dbl>     <dbl>
## 1 mt_model(Intercept)                  707.        9.93    71.2   1.54e-218
## 2 mt_modelfactor(county)Butte           -6.11      9.48    -0.645 5.19e-  1
## 3 mt_modelfactor(county)Calaveras       -9.02     12.2     -0.737 4.61e-  1
## 4 mt_modelfactor(county)Contra Costa    -8.96      9.22    -0.971 3.32e-  1
## 5 mt_modelfactor(county)El Dorado      -12.3       9.05    -1.36  1.75e-  1
## 6 mt_modelfactor(county)Fresno         -10.9       9.09    -1.20  2.29e-  1
# Covariates
head(mt_model, 5)
##   (Intercept) factor(county)Butte factor(county)Calaveras
## 1           1                   0                       0
## 2           1                   1                       0
## 3           1                   1                       0
## 4           1                   1                       0
## 5           1                   1                       0
##   factor(county)Contra Costa factor(county)El Dorado factor(county)Fresno
## 1                          0                       0                    0
## 2                          0                       0                    0
## 3                          0                       0                    0
## 4                          0                       0                    0
## 5                          0                       0                    0
##   factor(county)Glenn factor(county)Humboldt factor(county)Imperial
## 1                   0                      0                      0
## 2                   0                      0                      0
## 3                   0                      0                      0
## 4                   0                      0                      0
## 5                   0                      0                      0
##   factor(county)Inyo factor(county)Kern factor(county)Kings factor(county)Lake
## 1                  0                  0                   0                  0
## 2                  0                  0                   0                  0
## 3                  0                  0                   0                  0
## 4                  0                  0                   0                  0
## 5                  0                  0                   0                  0
##   factor(county)Lassen factor(county)Los Angeles factor(county)Madera
## 1                    0                         0                    0
## 2                    0                         0                    0
## 3                    0                         0                    0
## 4                    0                         0                    0
## 5                    0                         0                    0
##   factor(county)Marin factor(county)Mendocino factor(county)Merced
## 1                   0                       0                    0
## 2                   0                       0                    0
## 3                   0                       0                    0
## 4                   0                       0                    0
## 5                   0                       0                    0
##   factor(county)Monterey factor(county)Nevada factor(county)Orange
## 1                      0                    0                    0
## 2                      0                    0                    0
## 3                      0                    0                    0
## 4                      0                    0                    0
## 5                      0                    0                    0
##   factor(county)Placer factor(county)Riverside factor(county)Sacramento
## 1                    0                       0                        0
## 2                    0                       0                        0
## 3                    0                       0                        0
## 4                    0                       0                        0
## 5                    0                       0                        0
##   factor(county)San Benito factor(county)San Bernardino factor(county)San Diego
## 1                        0                            0                       0
## 2                        0                            0                       0
## 3                        0                            0                       0
## 4                        0                            0                       0
## 5                        0                            0                       0
##   factor(county)San Joaquin factor(county)San Luis Obispo
## 1                         0                             0
## 2                         0                             0
## 3                         0                             0
## 4                         0                             0
## 5                         0                             0
##   factor(county)San Mateo factor(county)Santa Barbara factor(county)Santa Clara
## 1                       0                           0                         0
## 2                       0                           0                         0
## 3                       0                           0                         0
## 4                       0                           0                         0
## 5                       0                           0                         0
##   factor(county)Santa Cruz factor(county)Shasta factor(county)Siskiyou
## 1                        0                    0                      0
## 2                        0                    0                      0
## 3                        0                    0                      0
## 4                        0                    0                      0
## 5                        0                    0                      0
##   factor(county)Sonoma factor(county)Stanislaus factor(county)Sutter
## 1                    0                        0                    0
## 2                    0                        0                    0
## 3                    0                        0                    0
## 4                    0                        0                    0
## 5                    0                        0                    0
##   factor(county)Tehama factor(county)Trinity factor(county)Tulare
## 1                    0                     0                    0
## 2                    0                     0                    0
## 3                    0                     0                    0
## 4                    0                     0                    0
## 5                    0                     0                    0
##   factor(county)Tuolumne factor(county)Ventura factor(county)Yuba calwpct
## 1                      0                     0                  0  0.5102
## 2                      0                     0                  0 15.4167
## 3                      0                     0                  0 55.0323
## 4                      0                     0                  0 36.4754
## 5                      0                     0                  0 33.1086
##   mealpct computer   stravg
## 1  2.0408       67 17.72727
## 2 47.9167      101 21.81818
## 3 76.3226      169 18.67470
## 4 77.0492       85 17.35714
## 5 78.4270      171 18.54167
# Covariates coefficients from regression (including constant)
ar_fl_cova_esti <- as.matrix(rs_scr_on_str_tidy %>% filter(!str_detect(term, 'stravg')) %>% select(estimate))
ar_fl_main_esti <- as.matrix(rs_scr_on_str_tidy %>% filter(str_detect(term, 'stravg')) %>% select(estimate))
head(ar_fl_cova_esti, 5)
##        estimate
## [1,] 707.424626
## [2,]  -6.114316
## [3,]  -9.022511
## [4,]  -8.961224
## [5,] -12.312981
head(ar_fl_main_esti, 5)
##        estimate
## [1,] -0.8699505
# Select Matrix subcomponents
mt_cova <- as.matrix(as_tibble(mt_model) %>% select(-contains("stravg")))
# mt_intr <- model.matrix(~ factor(race) - 1)
mt_intr <- t(t(rep(1, dim(mt_model)[1])))

# Generate A_i, use mt_cova_wth_const
ar_Omega_m <- mt_cova %*% ar_fl_cova_esti
head(ar_Omega_m, 5)
##      estimate
## [1,] 706.2218
## [2,] 673.2570
## [3,] 657.0958
## [4,] 656.3883
## [5,] 655.5153
# Generate temporary theta_i (alpha elswhere, but theta here, because how student count will enter
ar_theta_m <- mt_intr %*% ar_fl_main_esti
head(ar_theta_m, 5)
##        estimate
## [1,] -0.8699505
## [2,] -0.8699505
## [3,] -0.8699505
## [4,] -0.8699505
## [5,] -0.8699505
# Beta
ar_beta_m <- rep(1/length(ar_Omega_m), times=length(ar_Omega_m))

# Dataframe of A and temporary theta
mt_A_theta_beta <- cbind(ar_Omega_m, ar_theta_m, ar_beta_m)

colnames(mt_A_theta_beta) <- c('Omega_i', 'theta_i', 'beta_i')

Uniform allocation and Maximum Per School Allocation

# Maximum Allocaiton D_max_i
# D_o_i: uniform allocation results, note ROUND
dfca <- dfca %>% mutate(D_max_i = floor(fl_fi_max*teachers)) %>%
          mutate(D_o_i = round(fl_fa_max*teachers))

# display
kable(dfca[0:25,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
id_i distcod county district grspan enrltot teachers calwpct mealpct computer testscr compstu expnstu str avginc elpct readscr mathscr stravg D_max_i D_o_i
1 75119 Alameda Sunol Glen Unified KK-08 195 11 0.5102 2.0408 67 690.80 0.3435898 6384.911 17.88991 22.690001 0.000000 691.6 690.0 17.72727 11 2
2 61499 Butte Manzanita Elementary KK-08 240 11 15.4167 47.9167 101 661.20 0.4208333 5099.381 21.52466 9.824000 4.583334 660.5 661.9 21.81818 11 2
3 61549 Butte Thermalito Union Elementary KK-08 1550 83 55.0323 76.3226 169 643.60 0.1090323 5501.955 18.69723 8.978000 30.000002 636.3 650.9 18.67470 83 17
4 61457 Butte Golden Feather Union Elementary KK-08 243 14 36.4754 77.0492 85 647.70 0.3497942 7101.831 17.35714 8.978000 0.000000 651.9 643.5 17.35714 14 3
5 61523 Butte Palermo Union Elementary KK-08 1335 72 33.1086 78.4270 171 640.85 0.1280899 5235.988 18.67133 9.080333 13.857677 641.8 639.9 18.54167 72 14
6 62042 Fresno Burrel Union Elementary KK-08 137 6 12.3188 86.9565 25 605.55 0.1824818 5580.147 21.40625 10.415000 12.408759 605.7 605.4 22.83333 6 1
7 68536 San Joaquin Holt Union Elementary KK-08 195 10 12.9032 94.6237 28 606.75 0.1435897 5253.331 19.50000 6.577000 68.717949 604.5 609.0 19.50000 10 2
8 63834 Kern Vineland Elementary KK-08 888 42 18.8063 100.0000 66 609.00 0.0743243 4565.746 20.89412 8.174000 46.959461 605.5 612.5 21.14286 42 8
9 62331 Fresno Orange Center Elementary KK-08 379 19 32.1900 93.1398 35 612.50 0.0923483 5355.548 19.94737 7.385000 30.079157 608.9 616.1 19.94737 19 4
10 67306 Sacramento Del Paso Heights Elementary KK-06 2247 108 78.9942 87.3164 0 612.65 0.0000000 5036.211 20.80556 11.613333 40.275921 611.9 613.4 20.80556 108 22
11 65722 Merced Le Grand Union Elementary KK-08 446 21 18.6099 85.8744 86 615.75 0.1928251 4547.692 21.23809 8.931000 52.914799 612.8 618.7 21.23810 21 4
12 62174 Fresno West Fresno Elementary KK-08 987 47 71.7131 98.6056 56 616.30 0.0567376 5447.345 21.00000 7.385000 54.609932 616.6 616.0 21.00000 47 9
13 71795 Tulare Allensworth Elementary KK-08 103 5 22.4299 98.1308 25 616.30 0.2427184 6567.149 20.60000 5.335000 42.718445 612.8 619.8 20.60000 5 1
14 72181 Tulare Sunnyside Union Elementary KK-08 487 24 24.6094 77.1484 0 616.30 0.0000000 4818.613 20.00822 8.279000 20.533880 610.0 622.6 20.29167 24 5
15 72298 Tulare Woodville Elementary KK-08 649 36 14.6379 76.2712 31 616.45 0.0477658 5621.456 18.02778 9.630000 80.123261 611.9 621.0 18.02778 36 7
16 72041 Tulare Pixley Union Elementary KK-08 852 42 24.2142 94.2957 80 617.35 0.0938967 6026.360 20.25196 7.454000 49.413143 614.8 619.9 20.28571 42 8
17 63594 Kern Lost Hills Union Elementary KK-08 491 29 11.2016 97.7597 100 618.05 0.2036660 6723.238 16.97787 6.216000 85.539719 611.7 624.4 16.93103 29 6
18 63370 Kern Buttonwillow Union Elementary KK-08 421 26 8.5511 77.9097 50 618.30 0.1187648 5589.885 16.50980 7.764000 58.907364 614.9 621.7 16.19231 26 5
19 64709 Los Angeles Lennox Elementary KK-08 6880 303 21.2824 94.9712 960 619.80 0.1395349 5064.616 22.70402 7.022000 77.005814 619.1 620.5 22.70627 303 61
20 63560 Kern Lamont Elementary KK-08 2688 135 23.4375 93.2292 139 620.30 0.0517113 5433.593 19.91111 5.699000 49.813988 621.3 619.3 19.91111 135 27
21 63230 Imperial Westmorland Union Elementary KK-08 440 24 34.7727 100.0000 69 620.50 0.1568182 5725.563 18.33333 7.941000 40.681820 615.6 625.4 18.33333 24 5
22 72058 Tulare Pleasant View Elementary KK-08 475 21 21.6495 91.5464 53 621.40 0.1115789 4542.105 22.61905 9.630000 16.210525 619.9 622.9 22.61905 21 4
23 63842 Kern Wasco Union Elementary KK-08 2538 130 18.9111 70.8167 169 621.75 0.0665879 5107.086 19.44828 7.405000 45.074863 622.9 620.6 19.52308 130 26
24 71811 Tulare Alta Vista Elementary KK-08 476 19 43.8559 100.0000 0 622.05 0.0000000 4659.662 25.05263 9.630000 39.075630 620.7 623.4 25.05263 19 4
25 65748 Merced Livingston Union Elementary KK-08 2357 114 16.8010 90.6237 216 622.60 0.0916419 4555.464 20.67544 8.019000 76.665253 619.5 625.7 20.67544 114 23

Generate df_casch_prep_i

Now we have all the ingredients for df_casch_prep_i, needing as listed in the introduction, see variables defined at the top of the file.

df_casch_prep_i <- cbind(dfca, mt_A_theta_beta)
ls_var_additional <- c('distcod', 'county', 'district', 'grspan', 'avginc', 'testscr')
df_casch_prep_i <- df_casch_prep_i %>% select(id_i, D_max_i, D_o_i, Omega_i, theta_i, beta_i, enrltot, teachers, stravg, one_of(ls_var_additional))

Save and Export df_casch_prep_i

df_opt_caschool_prep_i <- df_casch_prep_i
if (bl_save_rda) {
  usethis::use_data(df_opt_caschool_prep_i, df_opt_caschool_prep_i, overwrite = TRUE)
}

DF2: Effect of an Additional Teacher (df_input_il)

The objective of this section is the generate dataframe df_input_il as well as df_input_ib

Generate df_input_ib

ib df has has two columns, id, and marginal effects of allocations, in excess of what is considered in \(\A_{i,l=0}\).

# Generate marginal expected effect from uniform additional allocation
df_input_ib <- df_casch_prep_i %>% mutate(alpha_o_i = theta_i*enrltot*((1/(teachers+D_o_i)) - (1/(teachers)))) %>%
                                   mutate(A_i_l0 = Omega_i + theta_i*(enrltot/(teachers))) %>%
                                   select(id_i, A_i_l0, alpha_o_i, beta_i)
# view(df_casch_prep_i %>% select(id_i, theta_i, enrltot, teachers, D_o_i))

# display
kable(df_input_ib[0:25,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
id_i A_i_l0 alpha_o_i beta_i
1 690.8000 2.372592 0.002381
2 654.2762 2.920114 0.002381
3 640.8497 2.761831 0.002381
4 641.2885 2.664680 0.002381
5 639.3850 2.625868 0.002381
6 625.4803 2.837696 0.002381
7 612.8571 2.827339 0.002381
8 617.2157 2.942918 0.002381
9 624.6470 3.017952 0.002381
10 621.9968 3.063044 0.002381
11 626.0318 2.956175 0.002381
12 621.1129 2.936083 0.002381
13 621.7829 2.986830 0.002381
14 634.4715 3.043577 0.002381
15 636.8020 2.553091 0.002381
16 624.3424 2.823611 0.002381
17 622.0817 2.524999 0.002381
18 634.4041 2.272017 0.002381
19 620.7221 3.310311 0.002381
20 622.3484 2.886947 0.002381
21 622.0775 2.749844 0.002381
22 623.8981 3.148392 0.002381
23 635.8420 2.830685 0.002381
24 617.1388 3.790356 0.002381
25 623.6784 3.019650 0.002381

Uncount and Expand \(i\) DF to \(il\) DF

Following the describing at the top of the file for variables required for df_input_il.

# following: https://fanwangecon.github.io/R4Econ/summarize/count/fs_count_basics.html
# teachers is a count coloumn to expand by
# D_il is each incremental teacher
# teachers_addl is existing teacher level added up to current l
df_input_il <- df_casch_prep_i %>% uncount(D_max_i) %>%
                  group_by(id_i) %>%
                  mutate(D_il = row_number()) %>%
                  mutate(teachers_addl = teachers + D_il)

# Generate D_max_i again, which disapeared due to uncount
df_input_il <- df_input_il %>% mutate(D_max_i = floor(fl_fi_max*teachers))

# Generate alpha_i for each additional teacher
df_input_il <- df_input_il %>% mutate(alpha_il = theta_i*enrltot*((1/teachers_addl) - (1/(teachers_addl-1)))) %>%
                               mutate(A_il = Omega_i + theta_i*(enrltot/(teachers_addl-1))) %>%
                               rowid_to_column(var = "id_il")
# Select Subset of Columns
df_input_il <- df_input_il %>% ungroup() %>% select(id_i, id_il, D_max_i, D_il, A_il, alpha_il, beta_i)

# display
kable(df_input_il[0:25,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
id_i id_il D_max_i D_il A_il alpha_il beta_i
1 1 11 1 690.8000 1.2851542 0.002381
1 2 11 2 692.0851 1.0874381 0.002381
1 3 11 3 693.1726 0.9320898 0.002381
1 4 11 4 694.1047 0.8078112 0.002381
1 5 11 5 694.9125 0.7068348 0.002381
1 6 11 6 695.6193 0.6236778 0.002381
1 7 11 7 696.2430 0.5543802 0.002381
1 8 11 8 696.7974 0.4960244 0.002381
1 9 11 9 697.2934 0.4464220 0.002381
1 10 11 10 697.7398 0.4039056 0.002381
1 11 11 11 698.1437 0.3671869 0.002381
2 12 11 1 654.2762 1.5817282 0.002381
2 13 11 2 655.8580 1.3383854 0.002381
2 14 11 3 657.1963 1.1471875 0.002381
2 15 11 4 658.3435 0.9942291 0.002381
2 16 11 5 659.3378 0.8699505 0.002381
2 17 11 6 660.2077 0.7676034 0.002381
2 18 11 7 660.9753 0.6823141 0.002381
2 19 11 8 661.6576 0.6104916 0.002381
2 20 11 9 662.2681 0.5494424 0.002381
2 21 11 10 662.8176 0.4971146 0.002381
2 22 11 11 663.3147 0.4519223 0.002381
3 23 83 1 640.8497 0.1934055 0.002381
3 24 83 2 641.0432 0.1888548 0.002381
3 25 83 3 641.2320 0.1844628 0.002381

Graph \(A_{il}\) and \(\alpha_{il}\) Joint Distribution

# Graph of the Distribution of Alpha_i and A_i
scatter <- df_input_il %>% ggplot(aes(x=A_il)) +
      geom_point(aes(y=log(alpha_il)), size=4, shape=4, color="red") +
      geom_abline(intercept = 0, slope = 1) + # 45 degree line
      labs(title = paste0('Discrete Allocation\nCalifornia Test Score and Student Teacher Ratio\nThe Relationship between A_il and alpha_il'),
           x = 'A_il = EXAM(teacher current + n)',
           y = 'log(alpha_il = E(teacher + n + 1) - E(teacher + n))',
           caption = paste0('Stock and Watson California Test and STR')) +
      theme_bw()

print(scatter)

Save and Export df_input_il and df_input_ib

For functionalized reuse and testing.

df_opt_caschool_input_il <- df_input_il
if (bl_save_rda) {
  usethis::use_data(df_opt_caschool_input_il, df_opt_caschool_input_il, overwrite = TRUE)
}
df_opt_caschool_input_ib <- df_input_ib
if (bl_save_rda) {
  usethis::use_data(df_opt_caschool_input_ib, df_opt_caschool_input_ib, overwrite = TRUE)
}

DF3 and DF4: Optimal Target Queue (df_queue_il) and Allocation (df_alloc_i)

DF3: Optimal Target Queue (df_queue_il)

Number of Ranking Spots

In the problem here, I am expanding total teaching research by 10 percent, so what is the total number of teachers that are in all schools currently,

# What is the number of teachers we can increase by
fl_teacher_increase_number <- sum(df_casch_prep_i$teachers)*fl_fa_max
fl_teacher_increase_number <- floor(fl_teacher_increase_number)

Solve for Optimally Targeting Queue

Sort, and select top given total resource avaiable, The count the total allocation for each. This means to invoke the binary allocation function.

Given the \(Q_{il}\) ranking, do the following, for each \(\rho\):

  1. Select only relevant columns for current calulcation:
    • \(i\) indicator variable
    • \(l\) within i counter for additional increments
    • \(Q_{il}\) targeting queue ranking
  2. If \(Q_{il}\left(\rho\right) \le \widehat{W}\), set \(D^{\widehat{W},\text{BIN}}_{il} = 1\), otherwise \(0\)
  3. Group by and Sum for each \(i\) over \(l\), total will be between \(0\) and \(\bar{D}\), mutate new \(D_{i} = \sum_l 1\left\{ Q_{il} < \widehat{W} \right\}\)
  4. Loop over \(\rho\) and finish
# Call function to Solve for Optimal Targeting Queue
svr_rho <- 'rho'
svr_inpalc <- 'Q_il'
ls_df_queues <- ffp_opt_anlyz_rhgin_bin(df_input_il, svr_id_i = 'id_il',
                                        svr_A_i = 'A_il', svr_alpha_i = 'alpha_il', svr_beta_i = 'beta_i',
                                        ar_rho = ar_rho,
                                        svr_rho = svr_rho,
                                        svr_inpalc = svr_inpalc,
                                        svr_expout = 'opti_exp_outcome',
                                        verbose = TRUE)
## tibble [54,204 x 11] (S3: tbl_df/tbl/data.frame)
##  $ id_i     : int [1:54204] 1 1 1 1 1 1 1 1 1 1 ...
##  $ id_il    : int [1:54204] 1 2 3 4 5 6 7 8 9 10 ...
##  $ D_max_i  : num [1:54204] 11 11 11 11 11 11 11 11 11 11 ...
##  $ D_il     : int [1:54204] 1 2 3 4 5 6 7 8 9 10 ...
##  $ A_il     : num [1:54204] 691 692 693 694 695 ...
##  $ alpha_il : num [1:54204] 1.285 1.087 0.932 0.808 0.707 ...
##  $ beta_i   : num [1:54204] 0.00238 0.00238 0.00238 0.00238 0.00238 ...
##  $ rho_c1_rk: int [1:54204] 138 209 297 404 522 658 813 978 1165 1357 ...
##  $ rho_c2_rk: int [1:54204] 140 212 305 409 534 673 835 999 1192 1383 ...
##  $ rho_c3_rk: int [1:54204] 244 372 507 666 855 1063 1292 1525 1782 2050 ...
##  $ rho_c4_rk: int [1:54204] 36657 39093 41307 43280 45090 46600 47875 48958 49841 50512 ...
## Joining, by = "id_il"
# Primary Long File
df_queue_il_long <- ls_df_queues$df_all_rho_long %>%
  mutate(D_Wbin_il = case_when(!!sym(svr_inpalc) <= fl_teacher_increase_number ~ 1, TRUE ~ 0)) %>%
  left_join(df_input_il %>% select(id_i, id_il, D_max_i, D_il), by='id_il') %>%
  select(!!sym(svr_rho), id_i, id_il, D_max_i, D_il, !!sym(svr_inpalc), D_Wbin_il, A_il, alpha_il, beta_i)

# Results from optimal targeting
# wide frame is mainly for visualization and analysis
df_queue_il_wide <- ls_df_queues$df_all_rho %>%
  left_join(df_casch_prep_i %>% select(id_i, teachers, enrltot, theta_i), by='id_i') %>%
  select(id_i, id_il, teachers, enrltot, theta_i, D_max_i, D_il, A_il, alpha_il, beta_i, everything())

# display
kable(df_queue_il_wide[0:100,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
id_i id_il teachers enrltot theta_i D_max_i D_il A_il alpha_il beta_i rank_min rank_max avg_rank rho_c1_rk rho_c2_rk rho_c3_rk rho_c4_rk
1 1 11 195 -0.8699505 11 1 690.8000 1.2851542 0.002381 36657 138 9294.75 138 140 244 36657
1 2 11 195 -0.8699505 11 2 692.0851 1.0874381 0.002381 39093 209 9971.50 209 212 372 39093
1 3 11 195 -0.8699505 11 3 693.1726 0.9320898 0.002381 41307 297 10604.00 297 305 507 41307
1 4 11 195 -0.8699505 11 4 694.1047 0.8078112 0.002381 43280 404 11189.75 404 409 666 43280
1 5 11 195 -0.8699505 11 5 694.9125 0.7068348 0.002381 45090 522 11750.25 522 534 855 45090
1 6 11 195 -0.8699505 11 6 695.6193 0.6236778 0.002381 46600 658 12248.50 658 673 1063 46600
1 7 11 195 -0.8699505 11 7 696.2430 0.5543802 0.002381 47875 813 12703.75 813 835 1292 47875
1 8 11 195 -0.8699505 11 8 696.7974 0.4960244 0.002381 48958 978 13115.00 978 999 1525 48958
1 9 11 195 -0.8699505 11 9 697.2934 0.4464220 0.002381 49841 1165 13495.00 1165 1192 1782 49841
1 10 11 195 -0.8699505 11 10 697.7398 0.4039056 0.002381 50512 1357 13825.50 1357 1383 2050 50512
1 11 11 195 -0.8699505 11 11 698.1437 0.3671869 0.002381 51074 1577 14150.50 1577 1608 2343 51074
2 12 11 240 -0.8699505 11 1 654.2762 1.5817282 0.002381 3788 72 1004.00 78 78 72 3788
2 13 11 240 -0.8699505 11 2 655.8580 1.3383854 0.002381 4969 124 1335.75 125 124 125 4969
2 14 11 240 -0.8699505 11 3 657.1963 1.1471875 0.002381 6231 183 1696.25 183 184 187 6231
2 15 11 240 -0.8699505 11 4 658.3435 0.9942291 0.002381 7564 258 2086.75 258 259 266 7564
2 16 11 240 -0.8699505 11 5 659.3378 0.8699505 0.002381 8893 353 2492.25 353 356 367 8893
2 17 11 240 -0.8699505 11 6 660.2077 0.7676034 0.002381 10197 453 2895.25 453 456 475 10197
2 18 11 240 -0.8699505 11 7 660.9753 0.6823141 0.002381 11503 561 3307.75 561 562 605 11503
2 19 11 240 -0.8699505 11 8 661.6576 0.6104916 0.002381 12822 683 3734.25 683 687 745 12822
2 20 11 240 -0.8699505 11 9 662.2681 0.5494424 0.002381 14142 825 4177.50 825 833 910 14142
2 21 11 240 -0.8699505 11 10 662.8176 0.4971146 0.002381 15417 975 4609.75 975 980 1067 15417
2 22 11 240 -0.8699505 11 11 663.3147 0.4519223 0.002381 16665 1133 5043.75 1133 1136 1241 16665
3 23 83 1550 -0.8699505 83 1 640.8497 0.1934055 0.002381 3605 3132 3474.25 3605 3580 3132 3580
3 24 83 1550 -0.8699505 83 2 641.0432 0.1888548 0.002381 3727 3217 3586.00 3713 3687 3217 3727
3 25 83 1550 -0.8699505 83 3 641.2320 0.1844628 0.002381 3877 3315 3696.75 3812 3783 3315 3877
3 26 83 1550 -0.8699505 83 4 641.4165 0.1802223 0.002381 4025 3408 3810.25 3918 3890 3408 4025
3 27 83 1550 -0.8699505 83 5 641.5967 0.1761263 0.002381 4170 3514 3923.25 4019 3990 3514 4170
3 28 83 1550 -0.8699505 83 6 641.7728 0.1721684 0.002381 4325 3605 4039.25 4129 4098 3605 4325
3 29 83 1550 -0.8699505 83 7 641.9450 0.1683425 0.002381 4477 3718 4157.25 4232 4202 3718 4477
3 30 83 1550 -0.8699505 83 8 642.1133 0.1646426 0.002381 4617 3826 4277.25 4346 4320 3826 4617
3 31 83 1550 -0.8699505 83 9 642.2780 0.1610635 0.002381 4777 3931 4399.50 4461 4429 3931 4777
3 32 83 1550 -0.8699505 83 10 642.4390 0.1575997 0.002381 4923 4040 4519.00 4568 4545 4040 4923
3 33 83 1550 -0.8699505 83 11 642.5966 0.1542465 0.002381 5062 4150 4639.50 4685 4661 4150 5062
3 34 83 1550 -0.8699505 83 12 642.7509 0.1509992 0.002381 5209 4259 4761.50 4804 4774 4259 5209
3 35 83 1550 -0.8699505 83 13 642.9019 0.1478534 0.002381 5370 4377 4890.50 4923 4892 4377 5370
3 36 83 1550 -0.8699505 83 14 643.0497 0.1448049 0.002381 5523 4490 5013.25 5035 5005 4490 5523
3 37 83 1550 -0.8699505 83 15 643.1945 0.1418497 0.002381 5672 4597 5138.00 5153 5130 4597 5672
3 38 83 1550 -0.8699505 83 16 643.3364 0.1389841 0.002381 5831 4722 5270.00 5284 5243 4722 5831
3 39 83 1550 -0.8699505 83 17 643.4754 0.1362044 0.002381 6006 4839 5402.25 5398 5366 4839 6006
3 40 83 1550 -0.8699505 83 18 643.6116 0.1335073 0.002381 6177 4954 5537.00 5522 5495 4954 6177
3 41 83 1550 -0.8699505 83 19 643.7451 0.1308895 0.002381 6352 5077 5678.25 5655 5629 5077 6352
3 42 83 1550 -0.8699505 83 20 643.8760 0.1283479 0.002381 6526 5212 5817.25 5782 5749 5212 6526
3 43 83 1550 -0.8699505 83 21 644.0043 0.1258797 0.002381 6690 5326 5956.00 5921 5887 5326 6690
3 44 83 1550 -0.8699505 83 22 644.1302 0.1234820 0.002381 6856 5458 6096.00 6051 6019 5458 6856
3 45 83 1550 -0.8699505 83 23 644.2537 0.1211521 0.002381 7020 5575 6235.00 6186 6159 5575 7020
3 46 83 1550 -0.8699505 83 24 644.3748 0.1188876 0.002381 7175 5702 6375.50 6327 6298 5702 7175
3 47 83 1550 -0.8699505 83 25 644.4937 0.1166860 0.002381 7344 5830 6517.75 6467 6430 5830 7344
3 48 83 1550 -0.8699505 83 26 644.6104 0.1145450 0.002381 7507 5961 6662.25 6609 6572 5961 7507
3 49 83 1550 -0.8699505 83 27 644.7250 0.1124623 0.002381 7670 6079 6801.25 6747 6709 6079 7670
3 50 83 1550 -0.8699505 83 28 644.8374 0.1104360 0.002381 7831 6203 6945.50 6890 6858 6203 7831
3 51 83 1550 -0.8699505 83 29 644.9479 0.1084639 0.002381 8004 6333 7088.00 7028 6987 6333 8004
3 52 83 1550 -0.8699505 83 30 645.0563 0.1065442 0.002381 8159 6453 7226.25 7164 7129 6453 8159
3 53 83 1550 -0.8699505 83 31 645.1629 0.1046750 0.002381 8327 6587 7373.75 7311 7270 6587 8327
3 54 83 1550 -0.8699505 83 32 645.2675 0.1028546 0.002381 8494 6717 7519.25 7454 7412 6717 8494
3 55 83 1550 -0.8699505 83 33 645.3704 0.1010812 0.002381 8657 6836 7663.50 7596 7565 6836 8657
3 56 83 1550 -0.8699505 83 34 645.4715 0.0993533 0.002381 8829 6969 7812.50 7750 7702 6969 8829
3 57 83 1550 -0.8699505 83 35 645.5708 0.0976694 0.002381 8989 7101 7956.25 7885 7850 7101 8989
3 58 83 1550 -0.8699505 83 36 645.6685 0.0960279 0.002381 9166 7248 8108.50 8032 7988 7248 9166
3 59 83 1550 -0.8699505 83 37 645.7645 0.0944274 0.002381 9328 7386 8255.25 8174 8133 7386 9328
3 60 83 1550 -0.8699505 83 38 645.8589 0.0928666 0.002381 9489 7517 8401.50 8324 8276 7517 9489
3 61 83 1550 -0.8699505 83 39 645.9518 0.0913442 0.002381 9642 7660 8548.75 8467 8426 7660 9642
3 62 83 1550 -0.8699505 83 40 646.0432 0.0898589 0.002381 9800 7801 8696.00 8614 8569 7801 9800
3 63 83 1550 -0.8699505 83 41 646.1330 0.0884096 0.002381 9956 7949 8841.75 8748 8714 7949 9956
3 64 83 1550 -0.8699505 83 42 646.2214 0.0869951 0.002381 10122 8095 8993.00 8895 8860 8095 10122
3 65 83 1550 -0.8699505 83 43 646.3084 0.0856142 0.002381 10281 8245 9142.75 9042 9003 8245 10281
3 66 83 1550 -0.8699505 83 44 646.3940 0.0842659 0.002381 10437 8392 9293.75 9194 9152 8392 10437
3 67 83 1550 -0.8699505 83 45 646.4783 0.0829493 0.002381 10611 8543 9451.50 9346 9306 8543 10611
3 68 83 1550 -0.8699505 83 46 646.5613 0.0816632 0.002381 10776 8686 9601.25 9492 9451 8686 10776
3 69 83 1550 -0.8699505 83 47 646.6429 0.0804069 0.002381 10936 8830 9752.25 9646 9597 8830 10936
3 70 83 1550 -0.8699505 83 48 646.7233 0.0791793 0.002381 11091 8977 9899.50 9786 9744 8977 11091
3 71 83 1550 -0.8699505 83 49 646.8025 0.0779796 0.002381 11248 9135 10053.50 9935 9896 9135 11248
3 72 83 1550 -0.8699505 83 50 646.8805 0.0768070 0.002381 11408 9291 10206.25 10082 10044 9291 11408
3 73 83 1550 -0.8699505 83 51 646.9573 0.0756606 0.002381 11562 9448 10359.25 10232 10195 9448 11562
3 74 83 1550 -0.8699505 83 52 647.0329 0.0745397 0.002381 11729 9598 10519.00 10395 10354 9598 11729
3 75 83 1550 -0.8699505 83 53 647.1075 0.0734435 0.002381 11894 9754 10682.25 10561 10520 9754 11894
3 76 83 1550 -0.8699505 83 54 647.1809 0.0723714 0.002381 12052 9917 10845.00 10726 10685 9917 12052
3 77 83 1550 -0.8699505 83 55 647.2533 0.0713225 0.002381 12218 10076 11009.75 10893 10852 10076 12218
3 78 83 1550 -0.8699505 83 56 647.3246 0.0702963 0.002381 12381 10237 11170.75 11053 11012 10237 12381
3 79 83 1550 -0.8699505 83 57 647.3949 0.0692920 0.002381 12543 10403 11335.25 11218 11177 10403 12543
3 80 83 1550 -0.8699505 83 58 647.4642 0.0683092 0.002381 12704 10564 11497.50 11381 11341 10564 12704
3 81 83 1550 -0.8699505 83 59 647.5325 0.0673471 0.002381 12860 10736 11660.25 11547 11498 10736 12860
3 82 83 1550 -0.8699505 83 60 647.5999 0.0664052 0.002381 13021 10902 11825.75 11709 11671 10902 13021
3 83 83 1550 -0.8699505 83 61 647.6663 0.0654829 0.002381 13183 11073 11995.75 11887 11840 11073 13183
3 84 83 1550 -0.8699505 83 62 647.7318 0.0645797 0.002381 13347 11239 12160.75 12051 12006 11239 13347
3 85 83 1550 -0.8699505 83 63 647.7963 0.0636950 0.002381 13511 11402 12329.25 12224 12180 11402 13511
3 86 83 1550 -0.8699505 83 64 647.8600 0.0628284 0.002381 13674 11576 12501.50 12401 12355 11576 13674
3 87 83 1550 -0.8699505 83 65 647.9229 0.0619794 0.002381 13833 11756 12675.75 12578 12536 11756 13833
3 88 83 1550 -0.8699505 83 66 647.9848 0.0611474 0.002381 13998 11926 12850.25 12763 12714 11926 13998
3 89 83 1550 -0.8699505 83 67 648.0460 0.0603321 0.002381 14155 12104 13027.50 12948 12903 12104 14155
3 90 83 1550 -0.8699505 83 68 648.1063 0.0595330 0.002381 14317 12281 13205.25 13136 13087 12281 14317
3 91 83 1550 -0.8699505 83 69 648.1659 0.0587497 0.002381 14480 12453 13379.75 13315 13271 12453 14480
3 92 83 1550 -0.8699505 83 70 648.2246 0.0579817 0.002381 14636 12643 13563.50 13509 13466 12643 14636
3 93 83 1550 -0.8699505 83 71 648.2826 0.0572287 0.002381 14783 12827 13736.50 13692 13644 12827 14783
3 94 83 1550 -0.8699505 83 72 648.3398 0.0564903 0.002381 14935 13007 13918.75 13889 13844 13007 14935
3 95 83 1550 -0.8699505 83 73 648.3963 0.0557661 0.002381 15094 13193 14100.00 14077 14036 13193 15094
3 96 83 1550 -0.8699505 83 74 648.4521 0.0550557 0.002381 15248 13386 14283.50 14269 14231 13386 15248
3 97 83 1550 -0.8699505 83 75 648.5071 0.0543588 0.002381 15401 13576 14468.50 14472 14425 13576 15401
3 98 83 1550 -0.8699505 83 76 648.5615 0.0536750 0.002381 15555 13763 14649.50 14662 14618 13763 15555
3 99 83 1550 -0.8699505 83 77 648.6152 0.0530041 0.002381 15700 13949 14828.50 14852 14813 13949 15700
3 100 83 1550 -0.8699505 83 78 648.6682 0.0523456 0.002381 15850 14143 15011.75 15049 15005 14143 15850

Number of Ranking Spots

How many potential teacher spots are to be allocated?

# We can increase teacher count
cat('this is W = fl_teacher_increase_number:', fl_teacher_increase_number, '\n')
## this is W = fl_teacher_increase_number: 10840
# What is the number of candidate recipient now in il unit
cat('fl_fi_max:', fl_fi_max, '\n')
## fl_fi_max: 1
cat('this is N = total candidate slots = dim(df_queue_il_wide)[1]:', dim(df_queue_il_wide)[1], '\n')
## this is N = total candidate slots = dim(df_queue_il_wide)[1]: 54204

DF4a: Optimal Allocations (df_alloc_i)

Generate the df_alloc_i_long file.

Aggregate to get Optimal Allocation

The implementation below is actually different, uses the rho_long file

  1. Generate \(A_{il}\) from from long file with all \(\rho\)
  2. Join long file with wide file key variables, includes \(D_i\), individual max count as well as id.
  3. Also generate \(F_i = \frac{D^{\star}_i}{D_max_i}\)
# Generate D_i and F_i long
df_alloc_i_long <- df_queue_il_long %>%
  select(!!sym(svr_rho), id_i, D_max_i, D_Wbin_il) %>%
  group_by(id_i, !!sym(svr_rho)) %>%
  summarize(D_star_i = sum(D_Wbin_il), D_max_i = mean(D_max_i),
            F_i = D_star_i/D_max_i) %>%
  mutate(!!sym(svr_rho) := as.numeric(!!sym(svr_rho))) %>%
  arrange(id_i, !!sym(svr_rho))
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
# df_alloc_i_wide is for visualization etc
st_last_rho <- paste0(svr_rho, length(ar_rho))
df_alloc_i_wide <- df_alloc_i_long %>%
  select(id_i, !!sym(svr_rho), F_i, D_max_i) %>%
  pivot_wider(
    names_from = svr_rho,
    values_from = 'F_i'
  )
## Note: Using an external vector in selections is ambiguous.
## i Use `all_of(svr_rho)` instead of `svr_rho` to silence this message.
## i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
# Rename rho columns and merge with key district attributes
ls_st_vars_casch_prep <- c('id_i', 'distcod', 'county', 'district', 'grspan', 'avginc', 'testscr',
                           'enrltot', 'teachers', 'stravg')
df_alloc_i_wide <- df_alloc_i_wide %>%
  rename_at(vars(num_range('', paste0(seq(1, length(ar_rho))))),
            funs(paste0(svr_rho,.))) %>%
  left_join(df_casch_prep_i %>% select(one_of(ls_st_vars_casch_prep)),
            by='id_i') %>% select(one_of(ls_st_vars_casch_prep), everything()) %>%
  mutate(rho_diff = (!!sym(st_last_rho) - !!sym(paste0(svr_rho, '1'))))

# Display Results
kable(df_alloc_i_wide[1:420,] %>% mutate_if(is.numeric, round, 2)) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
## `mutate_if()` ignored the following grouping variables:
## Column `id_i`
id_i distcod county district grspan avginc testscr enrltot teachers stravg D_max_i rho1 rho2 rho3 rho4 rho_diff
1 75119 Alameda Sunol Glen Unified KK-08 22.69 690.80 195 11 17.73 11 1.00 1.00 1.00 0.00 -1.00
2 61499 Butte Manzanita Elementary KK-08 9.82 661.20 240 11 21.82 11 1.00 1.00 1.00 0.55 -0.45
3 61549 Butte Thermalito Union Elementary KK-08 8.98 643.60 1550 83 18.67 83 0.65 0.65 0.71 0.55 -0.10
4 61457 Butte Golden Feather Union Elementary KK-08 8.98 647.70 243 14 17.36 14 1.00 1.00 1.00 1.00 0.00
5 61523 Butte Palermo Union Elementary KK-08 9.08 640.85 1335 72 18.54 72 0.76 0.78 0.83 0.72 -0.04
6 62042 Fresno Burrel Union Elementary KK-08 10.41 605.55 137 6 22.83 6 1.00 1.00 1.00 1.00 0.00
7 68536 San Joaquin Holt Union Elementary KK-08 6.58 606.75 195 10 19.50 10 1.00 1.00 1.00 1.00 0.00
8 63834 Kern Vineland Elementary KK-08 8.17 609.00 888 42 21.14 42 1.00 1.00 1.00 1.00 0.00
9 62331 Fresno Orange Center Elementary KK-08 7.39 612.50 379 19 19.95 19 1.00 1.00 1.00 1.00 0.00
10 67306 Sacramento Del Paso Heights Elementary KK-06 11.61 612.65 2247 108 20.81 108 0.53 0.54 0.69 1.00 0.47
11 65722 Merced Le Grand Union Elementary KK-08 8.93 615.75 446 21 21.24 21 1.00 1.00 1.00 1.00 0.00
12 62174 Fresno West Fresno Elementary KK-08 7.39 616.30 987 47 21.00 47 1.00 1.00 1.00 1.00 0.00
13 71795 Tulare Allensworth Elementary KK-08 5.34 616.30 103 5 20.60 5 1.00 1.00 1.00 1.00 0.00
14 72181 Tulare Sunnyside Union Elementary KK-08 8.28 616.30 487 24 20.29 24 1.00 1.00 1.00 1.00 0.00
15 72298 Tulare Woodville Elementary KK-08 9.63 616.45 649 36 18.03 36 1.00 1.00 1.00 1.00 0.00
16 72041 Tulare Pixley Union Elementary KK-08 7.45 617.35 852 42 20.29 42 1.00 1.00 1.00 1.00 0.00
17 63594 Kern Lost Hills Union Elementary KK-08 6.22 618.05 491 29 16.93 29 1.00 1.00 1.00 1.00 0.00
18 63370 Kern Buttonwillow Union Elementary KK-08 7.76 618.30 421 26 16.19 26 1.00 1.00 1.00 1.00 0.00
19 64709 Los Angeles Lennox Elementary KK-08 7.02 619.80 6880 303 22.71 303 0.00 0.00 0.09 1.00 1.00
20 63560 Kern Lamont Elementary KK-08 5.70 620.30 2688 135 19.91 135 0.34 0.35 0.49 1.00 0.66
21 63230 Imperial Westmorland Union Elementary KK-08 7.94 620.50 440 24 18.33 24 1.00 1.00 1.00 1.00 0.00
22 72058 Tulare Pleasant View Elementary KK-08 9.63 621.40 475 21 22.62 21 1.00 1.00 1.00 1.00 0.00
23 63842 Kern Wasco Union Elementary KK-08 7.41 621.75 2538 130 19.52 130 0.35 0.35 0.43 0.70 0.35
24 71811 Tulare Alta Vista Elementary KK-08 9.63 622.05 476 19 25.05 19 1.00 1.00 1.00 1.00 0.00
25 65748 Merced Livingston Union Elementary KK-08 8.02 622.60 2357 114 20.68 114 0.48 0.49 0.63 1.00 0.52
26 72272 Tulare Woodlake Union Elementary KK-08 8.52 623.10 1588 85 18.68 85 0.64 0.64 0.75 1.00 0.36
27 65961 Monterey Alisal Union Elementary KK-06 7.98 623.20 7306 320 22.83 320 0.00 0.00 0.07 1.00 1.00
28 63313 Kern Arvin Union Elementary KK-08 7.30 623.45 2601 135 19.27 135 0.32 0.33 0.46 1.00 0.68
29 72199 Tulare Terra Bella Union Elementary KK-08 8.93 623.60 847 44 19.25 44 1.00 1.00 1.00 1.00 0.00
30 72215 Tulare Tipton Elementary KK-08 8.55 624.15 452 22 20.55 22 1.00 1.00 1.00 1.00 0.00
31 68379 San Diego San Ysidro Elementary KK-08 6.61 624.55 4142 201 20.61 201 0.11 0.12 0.19 0.52 0.40
32 75440 Monterey Soledad Unified KK-08 12.41 624.95 2102 100 21.02 100 0.60 0.61 0.79 1.00 0.40
33 64816 Los Angeles Mountain View Elementary KK-08 8.13 625.30 10012 465 21.53 465 0.00 0.00 0.00 1.00 1.00
34 66050 Monterey King City Union Elementary KK-08 11.43 625.85 2488 125 19.90 125 0.39 0.39 0.46 0.48 0.09
35 67819 San Bernardino Ontario-Montclair Elementary KK-08 11.72 626.10 25151 1187 21.19 1187 0.00 0.00 0.00 0.31 0.31
36 64758 Los Angeles Los Nietos Elementary KK-08 11.33 626.80 2267 104 21.80 104 0.60 0.61 0.72 1.00 0.40
37 65870 Merced Winton Elementary KK-08 9.60 626.90 1657 90 18.41 90 0.58 0.58 0.70 1.00 0.42
38 62380 Fresno Raisin City Elementary KK-08 14.56 627.10 284 18 15.78 18 1.00 1.00 1.00 1.00 0.00
39 68999 San Mateo Ravenswood City Elementary KK-08 22.06 627.25 5370 280 19.18 280 0.00 0.00 0.00 0.56 0.56
40 63578 Kern Richland-Lerdo Union Elementary KK-08 9.71 627.30 2471 122 20.25 122 0.42 0.43 0.56 1.00 0.58
41 72538 Ventura Oxnard Elementary KK-08 11.48 628.25 15386 669 23.00 669 0.00 0.00 0.00 0.23 0.23
42 65680 Merced El Nido Elementary KK-08 8.18 628.40 184 9 20.44 9 1.00 1.00 1.00 1.00 0.00
43 63461 Kern Fairfax Elementary KK-08 8.17 628.55 1217 61 19.95 61 1.00 1.00 1.00 1.00 0.00
44 63404 Kern Delano Union Elementary KK-08 7.50 628.65 6219 268 23.21 268 0.03 0.03 0.18 1.00 0.97
45 67199 Riverside Perris Elementary KK-06 10.05 628.75 4258 221 19.27 221 0.03 0.04 0.15 1.00 0.97
46 65078 Los Angeles Valle Lindo Elementary KK-08 7.33 629.80 1235 53 23.30 53 1.00 1.00 1.00 0.85 -0.15
47 69369 Santa Clara Alum Rock Union Elementary KK-08 12.58 630.35 16244 767 21.18 767 0.00 0.00 0.00 0.00 0.00
48 63438 Kern Edison Elementary KK-08 15.18 630.40 814 39 20.87 39 1.00 1.00 1.00 1.00 0.00
49 63321 Kern Bakersfield City Elementary KK-08 12.11 630.55 27176 1429 19.02 1429 0.00 0.00 0.00 0.23 0.23
50 69450 Santa Clara Franklin-McKinley Elementary KK-08 11.78 630.55 10696 488 21.92 488 0.00 0.00 0.00 0.11 0.11
51 64592 Los Angeles Hawthorne Elementary KK-08 14.06 631.05 8935 444 20.12 444 0.00 0.00 0.00 0.42 0.42
52 65193 Madera Chowchilla Elementary KK-08 10.47 631.40 1600 74 21.62 74 0.88 0.89 0.97 1.00 0.12
53 66142 Monterey Salinas City Elementary KK-06 13.41 631.85 9028 450 20.06 450 0.00 0.00 0.00 0.52 0.52
54 69120 Santa Barbara Santa Maria-Bonita Elementary KK-08 12.30 631.90 10625 521 20.39 521 0.00 0.00 0.00 0.10 0.10
55 65110 Los Angeles Whittier City Elementary KK-08 15.40 631.95 7151 319 22.42 319 0.00 0.00 0.00 0.14 0.14
56 64477 Los Angeles Eastside Union Elementary KK-08 13.76 632.00 2404 105 22.90 105 0.63 0.63 0.65 0.25 -0.38
57 64691 Los Angeles Lawndale Elementary KK-08 14.18 632.20 5804 283 20.51 283 0.00 0.00 0.03 0.69 0.69
58 67421 Sacramento Robla Elementary KK-06 8.86 632.25 2253 113 19.94 113 0.46 0.47 0.61 1.00 0.54
59 66191 Monterey Santa Rita Union Elementary KK-08 13.00 632.45 2807 126 22.28 126 0.47 0.47 0.53 0.50 0.03
60 72561 Ventura Rio Elementary KK-08 11.59 632.85 3074 143 21.50 143 0.35 0.36 0.42 0.50 0.15
61 72157 Tulare Strathmore Union Elementary KK-08 8.28 632.95 723 37 19.54 37 1.00 1.00 1.00 1.00 0.00
62 67397 Sacramento North Sacramento Elementary KK-06 10.91 633.05 5138 291 17.66 291 0.00 0.00 0.00 1.00 1.00
63 66423 Orange Anaheim Elementary KK-06 13.40 633.15 20927 954 21.94 954 0.00 0.00 0.00 0.25 0.25
64 63974 Kings Lemoore Union Elementary KK-08 11.08 633.65 3017 138 21.86 138 0.38 0.39 0.42 0.16 -0.22
65 63875 Kings Armona Union Elementary KK-08 9.08 633.90 957 50 19.14 50 1.00 1.00 1.00 1.00 0.00
66 63339 Kern Beardsley Elementary KK-08 13.39 634.00 1639 90 18.21 90 0.57 0.58 0.68 1.00 0.43
67 65037 Los Angeles South Whittier Elementary KK-08 14.60 634.05 4340 210 20.67 210 0.10 0.10 0.22 1.00 0.90
68 63917 Kings Hanford Elementary KK-08 11.12 634.10 5079 224 22.67 224 0.11 0.11 0.17 0.24 0.13
69 68221 San Diego National Elementary KK-06 8.42 634.10 6639 305 21.77 305 0.00 0.00 0.05 1.00 1.00
70 70904 Sonoma Roseland Elementary KK-06 11.66 634.15 1154 62 18.61 62 0.90 0.92 1.00 1.00 0.10
71 63420 Kern Di Giorgio Elementary KK-08 7.30 634.20 237 11 21.55 11 1.00 1.00 1.00 1.00 0.00
72 64642 Los Angeles Keppel Union Elementary KK-08 13.73 634.40 2987 141 21.18 141 0.35 0.35 0.42 0.53 0.18
73 63966 Kings Lakeside Union Elementary KK-08 11.12 634.55 499 30 16.63 30 1.00 1.00 1.00 1.00 0.00
74 65771 Merced Merced City Elementary KK-08 10.36 634.70 11474 543 21.13 543 0.00 0.00 0.00 0.39 0.39
75 69203 Santa Barbara Guadalupe Union Elementary KK-08 6.98 634.90 1088 55 19.78 55 1.00 1.00 1.00 1.00 0.00
76 67694 San Bernardino Cucamonga Elementary KK-08 14.47 634.95 2660 140 19.00 140 0.29 0.29 0.38 0.86 0.57
77 61705 Contra Costa Knightsen Elementary KK-08 14.65 635.05 353 20 17.65 20 1.00 1.00 1.00 0.00 -1.00
78 63008 Humboldt Rio Dell Elementary KK-08 10.63 635.20 329 19 17.32 19 1.00 1.00 1.00 1.00 0.00
79 70417 Siskiyou Montague Elementary KK-08 9.78 635.45 252 16 15.75 16 1.00 1.00 1.00 0.94 -0.06
80 70409 Siskiyou McCloud Union Elementary KK-08 10.66 635.60 175 12 14.58 12 1.00 1.00 1.00 1.00 0.00
81 72587 Ventura Santa Paula Elementary KK-08 11.94 635.60 3835 186 20.62 186 0.16 0.17 0.24 0.60 0.44
82 62539 Fresno West Park Elementary KK-08 7.39 635.75 314 19 16.53 19 1.00 1.00 1.00 1.00 0.00
83 65631 Merced Atwater Elementary KK-08 10.68 635.95 4458 211 21.13 211 0.10 0.11 0.18 0.60 0.50
84 65862 Merced Weaver Union Elementary KK-08 9.97 636.10 1313 75 17.51 75 0.68 0.69 0.77 0.93 0.25
85 62356 Fresno Pacific Union Elementary KK-08 8.26 636.50 474 26 18.23 26 1.00 1.00 1.00 1.00 0.00
86 75051 San Bernardino Lucerne Valley Unified KK-08 8.90 636.60 1114 58 19.21 58 1.00 1.00 1.00 0.71 -0.29
87 67231 Riverside Romoland Elementary KK-06 12.06 636.70 1358 65 20.89 65 0.97 0.98 1.00 1.00 0.03
88 64501 Los Angeles El Monte City Elementary KK-08 9.43 636.90 11629 546 21.30 546 0.00 0.00 0.00 0.57 0.57
89 63503 Kern Greenfield Union Elementary KK-08 8.92 636.95 6195 307 20.18 307 0.00 0.00 0.00 0.32 0.32
90 72033 Tulare Palo Verde Union Elementary KK-08 10.10 637.00 499 20 24.95 20 1.00 1.00 1.00 1.00 0.00
91 67322 Sacramento Elverta Joint Elementary KK-08 11.83 637.10 417 23 18.13 23 1.00 1.00 1.00 0.65 -0.35
92 64048 Lake Lucerne Elementary KK-08 11.55 637.35 300 15 20.00 15 1.00 1.00 1.00 1.00 0.00
93 69542 Santa Clara Luther Burbank Elementary KK-08 19.71 637.65 457 24 19.04 24 1.00 1.00 1.00 1.00 0.00
94 61382 Butte Bangor Union Elementary KK-08 7.11 637.95 146 8 18.25 8 1.00 1.00 1.00 0.75 -0.25
95 68858 San Mateo Bayshore Elementary KK-08 13.73 637.95 460 24 19.17 24 1.00 1.00 1.00 1.00 0.00
96 72017 Tulare Oak Valley Union Elementary KK-08 10.10 638.00 354 18 19.67 18 1.00 1.00 1.00 1.00 0.00
97 65151 Los Angeles Wilsona Elementary KK-08 13.76 638.20 1841 95 19.38 95 0.58 0.58 0.63 0.45 -0.13
98 63073 Imperial Brawley Elementary KK-08 9.66 638.30 3760 184 20.43 184 0.16 0.16 0.22 0.30 0.14
99 63198 Imperial Meadows Union Elementary KK-08 10.26 638.30 500 22 22.73 22 1.00 1.00 1.00 1.00 0.00
100 64717 Los Angeles Little Lake City Elementary KK-08 11.57 638.35 5112 247 20.70 247 0.01 0.01 0.06 0.10 0.09
101 63719 Kern Pond Union Elementary KK-08 7.41 638.55 146 8 18.25 8 1.00 1.00 1.00 1.00 0.00
102 63800 Kern Taft City Elementary KK-08 12.08 638.70 2141 106 20.20 106 0.52 0.53 0.59 0.60 0.08
103 71357 Sutter Brittan Elementary KK-08 11.28 639.25 610 31 19.68 31 1.00 1.00 1.00 1.00 0.00
104 65557 Mendocino Arena Union Elementary KK-08 10.03 639.30 337 17 19.82 17 1.00 1.00 1.00 1.00 0.00
105 67587 San Bernardino Adelanto Elementary KK-08 8.38 639.35 4501 228 19.74 228 0.03 0.03 0.09 0.28 0.25
106 67470 San Benito Hollister School District KK-08 13.63 639.50 5718 295 19.38 295 0.00 0.00 0.00 0.01 0.01
107 64857 Los Angeles Palmdale Elementary KK-08 14.13 639.75 19402 846 22.93 846 0.00 0.00 0.00 0.00 0.00
108 61507 Butte Oroville City Elementary KK-08 11.27 639.80 3401 176 19.32 176 0.15 0.16 0.21 0.25 0.10
109 63792 Kern Standard Elementary KK-08 13.39 639.85 2621 137 19.13 137 0.30 0.31 0.36 0.39 0.09
110 72447 Ventura Briggs Elementary KK-08 11.94 639.90 426 20 21.30 20 1.00 1.00 1.00 1.00 0.00
111 62323 Fresno Monroe Elementary KK-08 8.26 640.10 205 11 18.64 11 1.00 1.00 1.00 1.00 0.00
112 64667 Los Angeles Lancaster Elementary KK-08 14.23 640.15 13668 648 21.09 648 0.00 0.00 0.00 0.00 0.00
113 65177 Madera Alview-Dairyland Union Elementary KK-08 10.47 640.50 342 18 19.00 18 1.00 1.00 1.00 1.00 0.00
114 66589 Orange Magnolia Elementary KK-06 14.24 640.75 6518 332 19.63 332 0.00 0.00 0.00 0.15 0.15
115 71985 Tulare Liberty Elementary KK-08 14.07 640.90 239 12 19.92 12 1.00 1.00 1.00 1.00 0.00
116 69617 Santa Clara Mt. Pleasant Elementary KK-08 15.97 641.10 2911 139 20.94 139 0.35 0.35 0.37 0.00 -0.35
117 63123 Imperial El Centro Elementary KK-08 10.26 641.45 6272 297 21.12 297 0.00 0.00 0.00 0.36 0.36
118 68395 San Diego South Bay Union Elementary KK-06 10.60 641.45 10218 509 20.07 509 0.00 0.00 0.00 0.00 0.00
119 69914 Shasta Cascade Union Elementary KK-08 10.52 641.55 1735 87 19.94 87 0.67 0.67 0.72 0.59 -0.08
120 71969 Tulare Kings River Union Elementary KK-08 11.24 641.80 474 27 17.56 27 1.00 1.00 1.00 1.00 0.00
121 71548 Tehama Gerber Union Elementary KK-08 10.06 642.20 544 30 18.13 30 1.00 1.00 1.00 0.93 -0.07
122 71910 Tulare Exeter Union Elementary KK-08 11.18 642.20 1987 103 19.29 103 0.50 0.50 0.52 0.10 -0.41
123 62000 Fresno American Union Elementary KK-08 7.39 642.40 418 22 19.00 22 1.00 1.00 1.00 1.00 0.00
124 66167 Monterey San Antonio Union Elementary KK-08 13.58 642.75 196 10 19.60 10 1.00 1.00 1.00 1.00 0.00
125 71837 Tulare Burton Elementary KK-08 9.63 643.05 2208 114 19.37 114 0.44 0.44 0.46 0.04 -0.39
126 67157 Riverside Nuview Union Elementary KK-08 15.27 643.20 1255 55 22.82 55 1.00 1.00 1.00 0.25 -0.75
127 70615 Sonoma Bellevue Union Elementary KK-06 14.03 643.25 1469 78 18.83 78 0.72 0.72 0.82 1.00 0.28
128 64550 Los Angeles Garvey Elementary KK-08 10.24 643.40 7114 333 21.36 333 0.00 0.00 0.00 0.72 0.72
129 71498 Tehama Corning Union Elementary KK-08 9.48 643.40 1962 98 20.02 98 0.57 0.58 0.61 0.27 -0.31
130 68916 San Mateo Jefferson Elementary KK-08 15.03 643.50 7761 361 21.50 361 0.00 0.00 0.00 0.00 0.00
131 70185 Siskiyou Big Springs Union Elementary KK-08 9.78 643.50 216 14 15.43 14 1.00 1.00 1.00 0.29 -0.71
132 63487 Kern General Shafter Elementary KK-08 13.19 643.70 224 10 22.40 10 1.00 1.00 1.00 1.00 0.00
133 71308 Stanislaus Turlock Joint Elementary KK-08 12.22 643.70 7887 392 20.12 392 0.00 0.00 0.00 0.01 0.01
134 72421 Tuolumne Twain Harte-Long Barn Union Elementary KK-08 14.08 644.20 752 40 18.80 40 1.00 1.00 1.00 0.00 -1.00
135 69005 San Mateo Redwood City Elementary KK-08 25.49 644.20 9328 538 17.34 538 0.00 0.00 0.00 0.00 0.00
136 61846 El Dorado Camino Union Elementary KK-08 14.87 644.40 548 32 17.12 32 1.00 1.00 1.00 0.00 -1.00
137 65813 Merced Plainsburg Union Elementary KK-08 9.97 644.45 104 5 20.80 5 1.00 1.00 1.00 1.00 0.00
138 68486 San Joaquin Banta Elementary KK-08 14.58 644.45 275 13 21.15 13 1.00 1.00 1.00 1.00 0.00
139 62513 Fresno Washington Colony Elementary KK-08 7.39 644.50 443 24 18.46 24 1.00 1.00 1.00 1.00 0.00
140 67405 Sacramento Rio Linda Union Elementary KK-06 12.34 644.55 10337 540 19.14 540 0.00 0.00 0.00 0.03 0.03
141 71050 Stanislaus Chatom Union Elementary KK-08 12.43 644.70 806 42 19.19 42 1.00 1.00 1.00 0.67 -0.33
142 73726 Merced Merced River Union Elementary KK-08 14.91 644.95 227 12 18.92 12 1.00 1.00 1.00 1.00 0.00
143 72462 Ventura Hueneme Elementary KK-08 12.67 645.10 8416 391 21.52 391 0.00 0.00 0.00 0.34 0.34
144 62737 Humboldt Cuddeback Union Elementary KK-08 10.33 645.25 149 8 18.62 8 1.00 1.00 1.00 1.00 0.00
145 62703 Humboldt Blue Lake Union Elementary KK-08 11.97 645.55 220 13 16.92 13 1.00 1.00 1.00 0.46 -0.54
146 68205 San Diego Lemon Grove Elementary KK-08 12.83 645.55 4612 233 19.79 233 0.02 0.02 0.06 0.02 0.00
147 64063 Lake Upper Lake Union Elementary KK-08 10.04 645.60 590 34 17.35 34 1.00 1.00 1.00 0.82 -0.18
148 62984 Humboldt Peninsula Union Elementary KK-08 13.34 645.75 133 8 16.62 8 1.00 1.00 1.00 1.00 0.00
149 72512 Ventura Ocean View Elementary KK-08 9.85 645.75 2440 121 20.17 121 0.42 0.42 0.43 0.00 -0.42
150 71647 Tehama Reeds Creek Elementary KK-08 11.43 646.00 133 6 22.17 6 1.00 1.00 1.00 0.33 -0.67
151 67280 Sacramento Arcohe Union Elementary KK-08 15.13 646.20 519 26 19.96 26 1.00 1.00 1.00 0.42 -0.58
152 68627 San Joaquin New Jerusalem Elementary KK-08 14.58 646.35 222 12 18.50 12 1.00 1.00 1.00 1.00 0.00
153 70243 Siskiyou Dunsmuir Elementary KK-08 10.27 646.40 285 19 15.00 19 1.00 1.00 1.00 1.00 0.00
154 71282 Stanislaus Stanislaus Union Elementary KK-08 15.59 646.50 3129 148 21.14 148 0.32 0.32 0.36 0.26 -0.05
155 62240 Fresno Kingsburg Joint Union Elementary KK-08 11.24 646.55 2019 103 19.60 103 0.52 0.51 0.50 0.00 -0.52
156 66456 Orange Buena Park Elementary KK-08 15.05 646.70 5620 267 21.05 267 0.00 0.00 0.01 0.00 0.00
157 66746 Orange Westminster Elementary KK-08 15.41 646.90 9775 484 20.20 484 0.00 0.00 0.00 0.00 0.00
158 63933 Kings Island Union Elementary KK-08 11.08 646.95 246 12 20.50 12 1.00 1.00 1.00 0.50 -0.50
159 72231 Tulare Tulare City Elementary KK-08 10.10 647.05 7210 360 20.03 360 0.00 0.00 0.00 0.14 0.14
160 68023 San Diego Chula Vista Elementary KK-06 14.30 647.25 21338 1052 20.28 1052 0.00 0.00 0.00 0.00 0.00
161 69880 Shasta Black Butte Union Elementary KK-08 11.80 647.30 477 27 17.67 27 1.00 1.00 1.00 0.37 -0.63
162 65763 Merced McSwain Union Elementary KK-08 9.97 647.60 727 40 18.18 40 1.00 1.00 1.00 0.00 -1.00
163 71381 Sutter Franklin Elementary KK-08 15.41 647.60 374 18 20.78 18 1.00 1.00 1.00 0.00 -1.00
164 68098 San Diego Escondido Union Elementary KK-08 15.29 648.00 18255 904 20.19 904 0.00 0.00 0.00 0.00 0.00
165 64485 Los Angeles East Whittier City Elementary KK-08 15.53 648.20 8787 411 21.38 411 0.00 0.00 0.00 0.00 0.00
166 73544 Kern Rio Bravo-Greeley Union Elementary KK-08 16.29 648.25 797 38 20.97 38 1.00 1.00 1.00 0.11 -0.89
167 71407 Sutter Marcum-Illinois Union Elementary KK-08 12.88 648.35 140 7 20.00 7 1.00 1.00 1.00 1.00 0.00
168 68437 San Diego Vallecitos Elementary KK-08 16.62 648.70 235 14 16.79 14 1.00 1.00 1.00 1.00 0.00
169 67918 San Bernardino Victor Elementary KK-06 12.55 648.95 8294 371 22.36 371 0.00 0.00 0.00 0.00 0.00
170 66696 Orange Savanna Elementary KK-06 14.26 649.15 2409 109 22.10 109 0.57 0.57 0.58 0.10 -0.47
171 71001 Sonoma West Side Union Elementary KK-06 18.33 649.30 150 8 18.75 8 1.00 1.00 1.00 0.00 -1.00
172 69971 Shasta Enterprise Elementary KK-08 12.75 649.50 3981 210 18.96 210 0.05 0.05 0.05 0.00 -0.05
173 71621 Tehama Red Bluff Union Elementary KK-08 11.43 649.70 2326 118 19.71 118 0.42 0.42 0.42 0.00 -0.42
174 72363 Tuolumne Jamestown Elementary KK-08 8.83 649.85 501 30 16.70 30 1.00 1.00 1.00 0.33 -0.67
175 70482 Siskiyou Weed Union Elementary KK-08 11.18 650.45 470 28 16.79 28 1.00 1.00 1.00 1.00 0.00
176 63032 Humboldt South Bay Union Elementary KK-06 14.23 650.55 575 35 16.43 35 1.00 1.00 1.00 0.29 -0.71
177 61655 Contra Costa Brentwood Union Elementary KK-08 15.03 650.60 3519 175 20.11 175 0.18 0.18 0.15 0.00 -0.18
178 72405 Tuolumne Summerville Elementary KK-08 10.52 650.65 474 26 18.23 26 1.00 1.00 1.00 0.50 -0.50
179 66860 Placer Ophir Elementary KK-08 18.63 650.90 223 12 18.58 12 1.00 1.00 1.00 0.00 -1.00
180 70821 Sonoma Montgomery Elementary KK-08 22.53 650.90 92 6 15.33 6 1.00 1.00 1.00 0.00 -1.00
181 70912 Sonoma Santa Rosa Elementary KK-06 18.30 651.15 4971 297 16.74 297 0.00 0.00 0.00 0.00 0.00
182 71266 Stanislaus Salida Union Elementary KK-08 11.89 651.20 2617 107 24.46 107 0.66 0.66 0.64 0.00 -0.66
183 70128 Shasta Shasta Union Elementary KK-08 9.93 651.35 242 13 18.62 13 1.00 1.00 1.00 0.38 -0.62
184 62802 Humboldt Fortuna Union Elementary KK-08 14.20 651.40 780 41 19.02 41 1.00 1.00 1.00 0.15 -0.85
185 72090 Tulare Rockford Elementary KK-08 9.63 651.45 324 15 21.60 15 1.00 1.00 1.00 1.00 0.00
186 62638 Glenn Plaza Elementary KK-08 10.64 651.80 140 7 20.00 7 1.00 1.00 1.00 0.29 -0.71
187 70813 Sonoma Monte Rio Union Elementary KK-08 14.48 651.85 181 10 18.10 10 1.00 1.00 1.00 1.00 0.00
188 64105 Lassen Janesville Union Elementary KK-08 13.47 651.90 516 26 19.85 26 1.00 1.00 1.00 0.00 -1.00
189 63172 Imperial Magnolia Union Elementary KK-08 9.66 652.00 108 5 21.60 5 1.00 1.00 1.00 0.60 -0.40
190 64188 Lassen Shaffer Union Elementary KK-08 12.71 652.10 419 19 22.05 19 1.00 1.00 1.00 0.53 -0.47
191 66506 Orange Fullerton Elementary KK-08 17.82 652.10 12567 546 23.02 546 0.00 0.00 0.00 0.00 0.00
192 70649 Sonoma Cinnabar Elementary KK-06 17.16 652.30 287 16 17.94 16 1.00 1.00 1.00 0.00 -1.00
193 69278 Santa Barbara Santa Barbara Elementary KK-08 19.59 652.30 6201 339 18.29 339 0.00 0.00 0.00 0.00 0.00
194 63016 Humboldt Rohnerville Elementary KK-08 14.20 652.35 577 30 19.23 30 1.00 1.00 1.00 0.13 -0.87
195 71431 Sutter Pleasant Grove Joint Union Elementary KK-08 11.91 652.40 170 8 21.25 8 1.00 1.00 1.00 1.00 0.00
196 73700 Shasta Mountain Union Elementary KK-08 13.39 652.40 164 8 20.50 8 1.00 1.00 1.00 1.00 0.00
197 63784 Kern South Fork Union Elementary KK-08 11.55 652.50 382 22 17.36 22 1.00 1.00 1.00 0.91 -0.09
198 68155 San Diego Jamul-Dulzura Union Elementary KK-08 19.03 652.85 1221 62 19.69 62 0.97 0.95 0.84 0.00 -0.97
199 69765 Santa Cruz Live Oak Elementary KK-08 16.41 653.10 2214 108 20.50 108 0.52 0.52 0.45 0.00 -0.52
200 67116 Riverside Menifee Union Elementary KK-08 14.06 653.40 4523 215 21.04 215 0.09 0.09 0.08 0.00 -0.09
201 63552 Kern Lakeside Union Elementary KK-08 19.07 653.50 793 40 19.82 40 1.00 1.00 1.00 0.00 -1.00
202 69724 Santa Clara Whisman Elementary KK-08 20.77 653.55 1678 88 19.07 88 0.62 0.62 0.57 0.00 -0.62
203 63180 Imperial McCabe Union Elementary KK-08 10.26 653.55 536 22 24.36 22 1.00 1.00 1.00 0.14 -0.86
204 68551 San Joaquin Lammersville Elementary KK-08 14.58 653.70 307 16 19.19 16 1.00 1.00 1.00 0.56 -0.44
205 71563 Tehama Lassen View Union Elementary KK-08 10.20 653.80 347 18 19.28 18 1.00 1.00 1.00 0.39 -0.61
206 62927 Humboldt Loleta Union Elementary KK-08 12.50 653.85 168 11 15.27 11 1.00 1.00 1.00 0.91 -0.09
207 70045 Shasta Junction Elementary KK-08 13.91 653.95 532 31 17.16 31 1.00 1.00 1.00 0.00 -1.00
208 64931 Los Angeles Rosemead Elementary KK-08 9.99 654.10 3272 150 21.81 150 0.33 0.33 0.43 0.89 0.57
209 66332 Nevada Grass Valley Elementary KK-08 13.71 654.20 2045 107 19.11 107 0.48 0.47 0.45 0.00 -0.48
210 71829 Tulare Buena Vista Elementary KK-08 10.10 654.20 156 6 26.00 6 1.00 1.00 1.00 1.00 0.00
211 63545 Kern Kernville Union Elementary KK-08 11.29 654.30 1129 62 18.21 62 0.89 0.89 0.94 0.58 -0.31
212 67348 Sacramento Galt Joint Union Elementary KK-08 13.23 654.60 3669 202 18.16 202 0.04 0.04 0.07 0.00 -0.04
213 67553 San Benito Southside Elementary KK-08 13.63 654.85 157 9 17.44 9 1.00 1.00 1.00 0.22 -0.78
214 68189 San Diego Lakeside Union Elementary KK-08 14.62 654.85 4928 229 21.52 229 0.07 0.07 0.03 0.00 -0.07
215 71423 Sutter Nuestro Elementary KK-08 8.78 654.90 103 5 20.60 5 1.00 1.00 1.00 1.00 0.00
216 61994 Fresno Alvina Elementary KK-08 10.34 655.05 175 10 17.50 10 1.00 1.00 1.00 1.00 0.00
217 61762 Contra Costa Oakley Union Elementary KK-08 16.32 655.05 4153 200 20.76 200 0.12 0.12 0.09 0.00 -0.12
218 70268 Siskiyou Etna Union Elementary KK-06 10.66 655.05 280 18 15.56 18 1.00 1.00 1.00 0.44 -0.56
219 68544 San Joaquin Jefferson Elementary KK-08 14.58 655.20 865 44 19.66 44 1.00 1.00 1.00 0.00 -1.00
220 69377 Santa Clara Berryessa Union Elementary KK-08 18.63 655.30 8735 408 21.41 408 0.00 0.00 0.00 0.00 0.00
221 63958 Kings Kit Carson Union Elementary KK-08 11.12 655.35 412 20 20.60 20 1.00 1.00 1.00 1.00 0.00
222 71290 Stanislaus Sylvan Union Elementary KK-08 14.60 655.35 6373 329 19.37 329 0.00 0.00 0.00 0.00 0.00
223 68635 San Joaquin Oak View Union Elementary KK-08 15.49 655.40 332 19 17.47 19 1.00 1.00 1.00 0.58 -0.42
224 66787 Placer Auburn Union Elementary KK-08 16.27 655.55 2903 138 21.04 138 0.36 0.36 0.33 0.00 -0.36
225 67504 San Benito North County Joint Union Elementary KK-08 13.63 655.70 565 30 18.83 30 1.00 1.00 1.00 0.77 -0.23
226 61945 El Dorado Pioneer Union Elementary KK-08 12.39 655.80 586 26 22.54 26 1.00 1.00 1.00 0.31 -0.69
227 67645 San Bernardino Central Elementary KK-08 15.33 655.85 5068 240 21.12 240 0.03 0.03 0.04 0.00 -0.03
228 70094 Shasta Pacheco Union Elementary KK-08 12.67 656.40 859 43 19.98 43 1.00 1.00 1.00 0.00 -1.00
229 66316 Nevada Chicago Park Elementary KK-08 13.71 656.50 145 10 14.50 10 1.00 1.00 1.00 0.00 -1.00
230 68874 San Mateo Brisbane Elementary KK-08 17.78 656.55 649 35 18.54 35 1.00 1.00 1.00 0.00 -1.00
231 63883 Kings Central Union Elementary KK-08 10.56 656.65 1789 96 18.64 96 0.53 0.53 0.55 0.11 -0.42
232 70011 Shasta Happy Valley Union Elementary KK-08 10.52 656.70 775 37 20.95 37 1.00 1.00 1.00 0.49 -0.51
233 61572 Calaveras Mark Twain Union Elementary KK-08 13.24 656.80 777 37 21.00 37 1.00 1.00 1.00 0.05 -0.95
234 65458 Marin San Rafael City Elementary KK-08 22.47 656.80 3518 188 18.71 188 0.10 0.10 0.10 0.00 -0.10
235 67991 San Diego Cajon Valley Union Elementary KK-08 15.68 657.00 19294 925 20.86 925 0.00 0.00 0.00 0.00 0.00
236 69393 Santa Clara Campbell Union Elementary KK-08 23.48 657.00 7661 386 19.85 386 0.00 0.00 0.00 0.00 0.00
237 71365 Sutter Browns Elementary KK-08 11.65 657.15 158 8 19.75 8 1.00 1.00 1.00 0.75 -0.25
238 66324 Nevada Clear Creek Elementary KK-08 16.36 657.40 117 6 19.50 6 1.00 1.00 1.00 0.50 -0.50
239 63057 Humboldt Trinidad Union Elementary KK-08 14.07 657.50 160 9 17.78 9 1.00 1.00 1.00 0.11 -0.89
240 70722 Sonoma Guerneville Elementary KK-08 13.44 657.55 511 27 18.93 27 1.00 1.00 1.00 0.41 -0.59
241 69013 San Mateo San Bruno Park Elementary KK-08 18.34 657.65 2770 140 19.79 140 0.31 0.31 0.26 0.00 -0.31
242 71472 Tehama Antelope Elementary KK-08 11.43 657.75 551 28 19.68 28 1.00 1.00 1.00 0.18 -0.82
243 66472 Orange Centralia Elementary KK-06 15.75 657.80 5205 242 21.51 242 0.04 0.04 0.04 0.00 -0.04
244 67702 San Bernardino Etiwanda Elementary KK-08 15.78 657.90 6437 279 23.07 279 0.00 0.00 0.00 0.00 0.00
245 65169 Los Angeles Wiseburn Elementary KK-08 14.06 658.00 1712 81 21.14 81 0.78 0.78 0.73 0.00 -0.78
246 63024 Humboldt Scotia Union Elementary KK-08 12.17 658.35 370 20 18.50 20 1.00 1.00 1.00 0.00 -1.00
247 67785 San Bernardino Mountain View Elementary KK-08 12.90 658.60 3182 153 20.80 153 0.29 0.28 0.25 0.00 -0.29
248 68791 San Luis Obispo Pleasant Valley Joint Union Elementary KK-06 10.97 658.80 139 7 19.86 7 1.00 1.00 1.00 0.14 -0.86
249 69625 Santa Clara Oak Grove Elementary KK-08 17.44 659.05 11855 589 20.13 589 0.00 0.00 0.00 0.00 0.00
250 61960 El Dorado Pollock Pines Elementary KK-08 14.76 659.15 1068 52 20.54 52 1.00 1.00 1.00 0.02 -0.98
251 64345 Los Angeles Castaic Union Elementary KK-08 14.60 659.35 2295 103 22.28 103 0.62 0.62 0.57 0.00 -0.62
252 63255 Inyo Bishop Union Elementary KK-08 13.52 659.40 1510 73 20.68 73 0.85 0.85 0.79 0.00 -0.85
253 69138 Santa Barbara Buellton Union Elementary KK-08 16.67 659.40 579 28 20.68 28 1.00 1.00 1.00 0.00 -1.00
254 75135 Madera Chawanakee Jt. Elementary KK-08 13.52 659.80 1012 53 19.09 53 1.00 1.00 0.98 0.00 -1.00
255 70508 Siskiyou Yreka Union Elementary KK-08 12.52 659.90 1212 69 17.57 69 0.75 0.75 0.72 0.00 -0.75
256 70599 Sonoma Alexander Valley Union Elementary KK-06 18.33 660.05 119 7 17.00 7 1.00 1.00 1.00 0.29 -0.71
257 66415 Nevada Twin Ridges Elementary KK-08 11.47 660.10 590 36 16.39 36 1.00 1.00 1.00 0.00 -1.00
258 72173 Tulare Sundale Union Elementary KK-08 10.10 660.20 546 28 19.50 28 1.00 1.00 1.00 0.54 -0.46
259 72207 Tulare Three Rivers Union Elementary KK-08 15.36 660.30 248 11 22.55 11 1.00 1.00 1.00 0.09 -0.91
260 72348 Tuolumne Columbia Union Elementary KK-08 10.31 660.75 461 26 17.73 26 1.00 1.00 1.00 0.27 -0.73
261 65102 Los Angeles Westside Union Elementary KK-08 16.99 660.95 6312 309 20.43 309 0.00 0.00 0.00 0.00 0.00
262 65649 Merced Ballico-Cressey Elementary KK-08 9.61 661.35 285 14 20.36 14 1.00 1.00 1.00 1.00 0.00
263 68973 San Mateo Millbrae Elementary KK-08 21.11 661.45 2325 115 20.22 115 0.46 0.46 0.37 0.00 -0.46
264 69435 Santa Clara Evergreen Elementary KK-08 16.47 661.60 11885 550 21.61 550 0.00 0.00 0.00 0.00 0.00
265 70730 Sonoma Harmony Union Elementary KK-08 18.37 661.60 564 27 20.89 27 1.00 1.00 1.00 0.00 -1.00
266 63362 Kern Panama Buena Vista Union Elementary KK-08 16.65 661.85 12380 620 19.97 620 0.00 0.00 0.00 0.00 0.00
267 68932 San Mateo Laguna Salada Union Elementary KK-08 18.54 661.85 3772 178 21.19 178 0.20 0.20 0.15 0.00 -0.20
268 72371 Tuolumne Sonora Elementary KK-08 14.18 661.85 895 48 18.65 48 1.00 1.00 1.00 0.00 -1.00
269 66910 Placer Roseville City Elementary KK-08 18.03 661.90 5714 278 20.55 278 0.00 0.00 0.00 0.00 0.00
270 71084 Stanislaus Gratton Elementary KK-08 13.59 661.90 105 6 17.50 6 1.00 1.00 1.00 0.00 -1.00
271 64196 Lassen Susanville Elementary KK-08 12.64 661.95 1449 77 18.82 77 0.73 0.71 0.68 0.00 -0.73
272 69872 Shasta Bella Vista Elementary KK-08 11.10 662.40 510 24 21.25 24 1.00 1.00 1.00 0.21 -0.79
273 71852 Tulare Columbine Elementary KK-08 7.50 662.40 160 8 20.00 8 1.00 1.00 1.00 1.00 0.00
274 64626 Los Angeles Hughes-Elizabeth Lakes Union Elementary KK-08 15.51 662.45 433 22 19.68 22 1.00 1.00 1.00 0.00 -1.00
275 69591 Santa Clara Mountain View Elementary KK-08 22.84 662.50 3186 164 19.43 164 0.20 0.20 0.20 0.00 -0.20
276 65045 Los Angeles Sulphur Springs Union Elementary KK-06 19.82 662.55 5010 239 20.96 239 0.03 0.03 0.02 0.00 -0.03
277 70680 Sonoma Forestville Union Elementary KK-08 16.35 662.55 717 36 19.92 36 1.00 1.00 1.00 0.00 -1.00
278 63750 Kern Rosedale Union Elementary KK-08 16.29 662.65 3548 171 20.75 171 0.22 0.21 0.16 0.00 -0.22
279 69948 Shasta Columbia Elementary KK-08 13.25 662.70 868 45 19.29 45 1.00 1.00 1.00 0.00 -1.00
280 66795 Placer Colfax Elementary KK-08 14.01 662.75 507 27 18.78 27 1.00 1.00 1.00 0.00 -1.00
281 70425 Siskiyou Mt. Shasta Union Elementary KK-08 14.16 662.90 822 47 17.49 47 1.00 1.00 1.00 0.00 -1.00
282 70870 Sonoma Piner-Olivet Union Elementary KK-06 15.77 663.35 1792 89 20.13 89 0.66 0.65 0.57 0.00 -0.66
283 65185 Madera Bass Lake Joint Elementary KK-08 14.48 663.45 1202 62 19.39 62 0.95 0.95 0.87 0.00 -0.95
284 62745 Humboldt Cutten Elementary KK-06 14.21 663.50 515 27 19.07 27 1.00 1.00 1.00 0.00 -1.00
285 61952 El Dorado Placerville Union Elementary KK-08 15.17 663.85 1354 67 20.21 67 0.91 0.91 0.87 0.00 -0.91
286 71035 Sonoma Wright Elementary KK-06 12.58 663.85 1252 65 19.26 65 0.89 0.89 0.86 0.00 -0.89
287 71522 Tehama Evergreen Union Elementary KK-08 10.55 663.90 823 46 17.89 46 1.00 1.00 1.00 0.07 -0.93
288 70847 Sonoma Old Adobe Union Elementary KK-06 16.96 664.00 2231 114 19.57 114 0.45 0.44 0.35 0.00 -0.45
289 71019 Sonoma Wilmar Union Elementary KK-06 17.71 664.00 271 14 19.36 14 1.00 1.00 1.00 0.00 -1.00
290 66761 Placer Ackerman Elementary KK-08 16.27 664.15 309 16 19.31 16 1.00 1.00 1.00 0.06 -0.94
291 69815 Santa Cruz Santa Cruz City Elementary KK-06 17.90 664.15 3005 159 18.90 159 0.20 0.20 0.15 0.00 -0.20
292 62679 Humboldt Arcata Elementary KK-08 11.83 664.30 966 48 20.12 48 1.00 1.00 1.00 0.06 -0.94
293 67595 San Bernardino Alta Loma Elementary KK-08 18.62 664.40 7710 327 23.58 327 0.00 0.00 0.00 0.00 0.00
294 66837 Placer Foresthill Union Elementary KK-08 12.43 664.45 762 36 21.17 36 1.00 1.00 1.00 0.00 -1.00
295 61929 El Dorado Mother Lode Union Elementary KK-08 15.17 664.70 1708 89 19.19 89 0.62 0.62 0.56 0.00 -0.62
296 66613 Orange Ocean View Elementary KK-08 20.88 664.75 9850 489 20.14 489 0.00 0.00 0.00 0.00 0.00
297 62596 Glenn Lake Elementary KK-08 10.64 664.95 129 5 25.80 5 1.00 1.00 1.00 0.80 -0.20
298 69039 San Mateo San Mateo-Foster City Elementary KK-08 25.03 664.95 10619 566 18.76 566 0.00 0.00 0.00 0.00 0.00
299 69195 Santa Barbara Goleta Union Elementary KK-06 16.76 665.10 4521 237 19.08 237 0.00 0.00 0.00 0.00 0.00
300 67736 San Bernardino Helendale Elementary KK-08 15.30 665.20 580 29 20.00 29 1.00 1.00 1.00 0.03 -0.97
301 70854 Sonoma Petaluma City Elementary KK-06 17.37 665.35 2569 138 18.62 138 0.28 0.28 0.23 0.00 -0.28
302 69690 Santa Clara Sunnyvale Elementary KK-08 22.10 665.65 6022 287 20.98 287 0.00 0.00 0.00 0.00 0.00
303 69179 Santa Barbara College Elementary KK-08 22.84 665.90 670 34 19.71 34 1.00 1.00 1.00 0.00 -1.00
304 68197 San Diego La Mesa-Spring Valley KK-08 18.32 665.95 14708 701 20.98 701 0.00 0.00 0.00 0.00 0.00
305 66530 Orange Huntington Beach City Elementary KK-08 25.03 666.00 6601 305 21.64 305 0.00 0.00 0.00 0.00 0.00
306 69336 Santa Barbara Solvang Elementary KK-08 21.96 666.05 675 34 19.85 34 1.00 1.00 1.00 0.00 -1.00
307 69849 Santa Cruz Soquel Elementary KK-08 18.80 666.10 2458 124 19.82 124 0.40 0.39 0.31 0.00 -0.40
308 62554 Glenn Capay Joint Union Elementary KK-08 10.64 666.15 144 8 18.00 8 1.00 1.00 1.00 0.12 -0.88
309 70714 Sonoma Gravenstein Union Elementary KK-08 17.51 666.15 573 30 19.10 30 1.00 1.00 1.00 0.00 -1.00
310 66381 Nevada Pleasant Valley Elementary KK-08 18.59 666.45 721 36 20.03 36 1.00 1.00 1.00 0.00 -1.00
311 63990 Kings Pioneer Union Elementary KK-08 11.12 666.55 992 47 21.11 47 1.00 1.00 1.00 0.00 -1.00
312 68361 San Diego Santee Elementary KK-08 14.10 666.60 8432 360 23.42 360 0.00 0.00 0.00 0.00 0.00
313 64113 Lassen Johnstonville Elementary KK-08 12.64 666.65 244 11 22.18 11 1.00 1.00 1.00 0.45 -0.55
314 72553 Ventura Pleasant Valley Elementary KK-08 20.94 666.65 7116 357 19.93 357 0.00 0.00 0.00 0.00 0.00
315 72355 Tuolumne Curtis Creek Elementary KK-08 14.18 666.70 830 47 17.66 47 1.00 1.00 1.00 0.00 -1.00
316 70300 Siskiyou Fort Jones Union Elementary KK-06 11.83 666.85 160 11 14.55 11 1.00 1.00 1.00 0.45 -0.55
317 70805 Sonoma Mark West Union Elementary KK-06 18.67 666.85 1588 83 19.13 83 0.67 0.66 0.58 0.00 -0.67
318 67967 San Diego Alpine Union Elementary KK-08 17.33 667.15 2272 109 20.84 109 0.52 0.52 0.41 0.00 -0.52
319 70938 Sonoma Sebastopol Union Elementary KK-08 17.51 667.20 1425 72 19.79 72 0.83 0.82 0.72 0.00 -0.83
320 62828 Humboldt Freshwater Elementary KK-06 15.57 667.45 245 13 18.85 13 1.00 1.00 1.00 0.00 -1.00
321 63693 Kern Norris Elementary KK-08 15.57 667.45 1349 65 20.75 65 0.97 0.97 0.83 0.00 -0.97
322 72132 Tulare Springville Union Elementary KK-08 15.75 667.60 400 22 18.18 22 1.00 1.00 1.00 0.00 -1.00
323 69575 Santa Clara Moreland Elementary KK-08 20.47 668.00 4632 245 18.91 245 0.00 0.00 0.00 0.00 0.00
324 63610 Kern Maple Elementary KK-08 9.71 668.10 224 9 24.89 9 1.00 1.00 1.00 0.78 -0.22
325 63941 Kings Kings River-Hardwick Union Elementary KK-08 11.12 668.40 576 31 18.58 31 1.00 1.00 1.00 0.00 -1.00
326 68163 San Diego Julian Union Elementary KK-08 16.32 668.60 451 25 18.04 25 1.00 1.00 1.00 0.00 -1.00
327 68007 San Diego Cardiff Elementary KK-06 21.97 668.65 900 51 17.65 51 1.00 1.00 0.90 0.00 -1.00
328 72108 Tulare Saucelito Elementary KK-08 8.93 668.80 118 6 19.67 6 1.00 1.00 1.00 1.00 0.00
329 67975 San Diego Bonsall Union Elementary KK-08 20.00 668.90 1457 73 19.96 73 0.82 0.82 0.77 0.00 -0.82
330 66480 Orange Cypress Elementary KK-06 18.83 668.95 4734 233 20.32 233 0.03 0.03 0.00 0.00 -0.03
331 64766 Los Angeles Lowell Joint Elementary KK-08 18.12 669.10 3303 146 22.62 146 0.37 0.37 0.31 0.00 -0.37
332 64832 Los Angeles Newhall Elementary KK-06 23.67 669.30 6055 287 21.10 287 0.00 0.00 0.00 0.00 0.00
333 65359 Marin Lagunitas Elementary KK-08 22.14 669.30 424 23 18.43 23 1.00 1.00 1.00 0.00 -1.00
334 69385 Santa Clara Cambrian Elementary KK-08 20.55 669.35 2801 139 20.15 139 0.32 0.32 0.26 0.00 -0.32
335 71654 Tehama Richfield Elementary KK-08 9.48 669.35 187 10 18.70 10 1.00 1.00 1.00 0.30 -0.70
336 62794 Humboldt Fieldbrook Elementary KK-08 11.83 669.80 129 7 18.43 7 1.00 1.00 1.00 0.00 -1.00
337 68049 San Diego Dehesa Elementary KK-06 18.80 669.85 188 9 20.89 9 1.00 1.00 1.00 0.22 -0.78
338 69955 Shasta Cottonwood Union Elementary KK-08 10.55 669.95 1212 66 18.36 66 0.83 0.83 0.79 0.00 -0.83
339 63479 Kern Fruitvale Elementary KK-08 15.52 670.00 2596 135 19.23 135 0.32 0.31 0.26 0.00 -0.32
340 69708 Santa Clara Union Elementary KK-08 21.63 670.70 4925 254 19.39 254 0.00 0.00 0.00 0.00 0.00
341 66498 Orange Fountain Valley Elementary KK-08 21.10 671.25 6257 289 21.65 289 0.00 0.00 0.00 0.00 0.00
342 61879 El Dorado Gold Oak Union Elementary KK-08 15.17 671.30 868 45 19.29 45 1.00 1.00 1.00 0.00 -1.00
343 61838 El Dorado Buckeye Union Elementary KK-08 19.12 671.60 3787 186 20.36 186 0.15 0.15 0.09 0.00 -0.15
344 75085 Placer Rocklin Unified KK-08 17.62 671.60 6423 306 20.99 306 0.00 0.00 0.00 0.00 0.00
345 61887 El Dorado Gold Trail Union Elementary KK-08 15.17 671.65 678 35 19.37 35 1.00 1.00 1.00 0.00 -1.00
346 62885 Humboldt Hydesville Elementary KK-08 10.64 671.70 162 8 20.25 8 1.00 1.00 1.00 0.25 -0.75
347 64998 Los Angeles Saugus Union Elementary KK-06 20.74 671.75 8529 408 20.90 408 0.00 0.00 0.00 0.00 0.00
348 66845 Placer Loomis Union Elementary KK-08 21.57 671.90 1862 89 20.92 89 0.69 0.69 0.60 0.00 -0.69
349 66886 Placer Placer Hills Union Elementary KK-08 17.66 671.90 1452 70 20.74 70 0.90 0.89 0.74 0.00 -0.90
350 70672 Sonoma Dunham Elementary KK-06 17.71 671.95 155 8 19.38 8 1.00 1.00 1.00 0.00 -1.00
351 69021 San Mateo San Carlos Elementary KK-08 27.82 672.05 2536 127 19.97 127 0.38 0.38 0.27 0.00 -0.38
352 66399 Nevada Ready Springs Union Elementary KK-08 18.59 672.05 567 30 18.90 30 1.00 1.00 1.00 0.00 -1.00
353 65219 Madera Coarsegold Union Elementary KK-08 14.26 672.30 953 53 17.98 53 1.00 1.00 0.92 0.00 -1.00
354 68726 San Luis Obispo Cayucos Elementary KK-08 22.76 672.35 296 15 19.73 15 1.00 1.00 1.00 0.00 -1.00
355 64170 Lassen Richmond Elementary KK-08 12.64 672.45 198 9 22.00 9 1.00 1.00 1.00 0.00 -1.00
356 62109 Fresno Clay Joint Elementary KK-08 11.24 672.55 218 10 21.80 10 1.00 1.00 1.00 0.20 -0.80
357 70995 Sonoma Waugh Elementary KK-06 16.96 672.70 734 36 20.39 36 1.00 1.00 1.00 0.00 -1.00
358 70979 Sonoma Two Rock Union Elementary KK-06 17.71 673.05 189 12 15.75 12 1.00 1.00 1.00 0.00 -1.00
359 68866 San Mateo Belmont-Redwood Shores Elementary KK-08 25.62 673.25 2528 138 18.32 138 0.27 0.26 0.17 0.00 -0.27
360 61978 El Dorado Rescue Union Elementary KK-08 18.73 673.30 2987 154 19.40 154 0.23 0.23 0.17 0.00 -0.23
361 66779 Placer Alta-Dutch Flat Union Elementary KK-08 13.44 673.55 208 11 18.91 11 1.00 1.00 1.00 0.09 -0.91
362 68353 San Diego San Pasqual Union Elementary KK-08 15.18 673.55 379 23 16.48 23 1.00 1.00 1.00 0.00 -1.00
363 61911 El Dorado Latrobe Elementary KK-08 19.12 673.90 145 9 16.11 9 1.00 1.00 1.00 0.00 -1.00
364 66407 Nevada Union Hill Elementary KK-08 13.71 674.25 706 38 18.58 38 1.00 1.00 1.00 0.00 -1.00
365 70961 Sonoma Twin Hills Union Elementary KK-08 17.51 675.40 878 48 18.29 48 1.00 1.00 1.00 0.00 -1.00
366 62976 Humboldt Pacific Union Elementary KK-08 11.83 675.70 594 33 18.00 33 1.00 1.00 1.00 0.00 -1.00
367 71696 Trinity Douglas City Elementary KK-08 13.27 676.15 139 7 19.86 7 1.00 1.00 1.00 0.00 -1.00
368 66373 Nevada Pleasant Ridge Union Elementary KK-08 16.36 676.55 2089 103 20.28 103 0.54 0.54 0.45 0.00 -0.54
369 66852 Placer Newcastle Elementary KK-08 18.63 676.60 326 16 20.38 16 1.00 1.00 1.00 0.00 -1.00
370 72470 Ventura Mesa Union Elementary KK-08 23.73 676.85 516 22 23.45 22 1.00 1.00 1.00 0.09 -0.91
371 71787 Trinity Weaverville Elementary KK-08 12.93 676.95 449 26 17.27 26 1.00 1.00 1.00 0.00 -1.00
372 70078 Shasta North Cow Creek Elementary KK-08 13.91 677.25 297 15 19.80 15 1.00 1.00 1.00 0.00 -1.00
373 66340 Nevada Nevada City Elementary KK-08 15.43 677.95 1579 80 19.74 80 0.72 0.72 0.64 0.00 -0.72
374 62893 Humboldt Jacoby Creek Elementary KK-08 15.38 678.05 383 20 19.15 20 1.00 1.00 1.00 0.00 -1.00
375 70698 Sonoma Fort Ross Elementary KK-08 22.53 678.40 81 5 16.20 5 1.00 1.00 1.00 0.00 -1.00
376 68080 San Diego Encinitas Union Elementary KK-06 23.81 678.80 5259 262 20.07 262 0.00 0.00 0.00 0.00 0.00
377 65318 Marin Dixie Elementary KK-08 24.60 679.40 1960 109 17.98 109 0.41 0.41 0.28 0.00 -0.41
378 69492 Santa Clara Lakeside Joint Elementary KK-06 36.17 679.50 151 9 16.78 9 1.00 1.00 1.00 0.00 -1.00
379 64600 Los Angeles Hermosa Beach City Elementary KK-08 33.46 679.65 946 49 19.31 49 1.00 1.00 1.00 0.00 -1.00
380 70896 Sonoma Rincon Valley Union Elementary KK-06 20.48 679.75 2707 141 19.20 141 0.28 0.28 0.22 0.00 -0.28
381 66233 Monterey Washington Union Elementary KK-08 20.13 679.80 919 47 19.55 47 1.00 1.00 1.00 0.00 -1.00
382 70623 Sonoma Bennett Valley Union Elementary KK-06 19.35 680.05 945 46 20.54 46 1.00 1.00 1.00 0.00 -1.00
383 69500 Santa Clara Loma Prieta Joint Union Elemen KK-08 36.17 680.45 738 40 18.45 40 1.00 1.00 1.00 0.00 -1.00
384 70789 Sonoma Kenwood Elementary KK-06 22.86 681.30 164 11 14.91 11 1.00 1.00 1.00 0.00 -1.00
385 70797 Sonoma Liberty Elementary KK-06 17.71 681.30 167 11 15.18 11 1.00 1.00 1.00 0.00 -1.00
386 71142 Stanislaus Knights Ferry Elementary KK-08 14.18 681.60 125 7 17.86 7 1.00 1.00 1.00 0.00 -1.00
387 65334 Marin Kentfield Elementary KK-08 41.09 681.90 1091 62 17.60 62 0.85 0.84 0.65 0.00 -0.85
388 69104 Santa Barbara Ballard Elementary KK-06 21.96 682.15 134 6 22.33 6 1.00 1.00 1.00 0.00 -1.00
389 70839 Sonoma Oak Grove Union Elementary KK-08 16.06 682.45 600 32 18.75 32 1.00 1.00 1.00 0.00 -1.00
390 75002 Marin Ross Valley Elementary KK-08 25.74 682.55 1803 100 18.03 100 0.48 0.47 0.33 0.00 -0.48
391 69773 Santa Cruz Mountain Elementary KK-06 20.47 682.65 158 8 19.75 8 1.00 1.00 1.00 0.00 -1.00
392 68882 San Mateo Burlingame Elementary KK-08 35.81 683.35 2392 127 18.83 127 0.34 0.34 0.24 0.00 -0.34
393 70003 Shasta Grant Elementary KK-08 13.57 683.40 526 28 18.79 28 1.00 1.00 1.00 0.00 -1.00
394 69757 Santa Cruz Happy Valley Elementary KK-06 20.09 684.30 141 7 20.14 7 1.00 1.00 1.00 0.00 -1.00
395 69732 Santa Cruz Bonny Doon Union Elementary KK-06 18.28 684.35 235 13 18.08 13 1.00 1.00 1.00 0.00 -1.00
396 61812 Contra Costa Walnut Creek Elementary KK-08 25.24 684.80 3280 158 20.76 158 0.27 0.26 0.18 0.00 -0.27
397 69211 Santa Barbara Hope Elementary KK-06 25.06 684.95 1254 57 22.00 57 1.00 1.00 0.96 0.00 -1.00
398 65367 Marin Larkspur Elementary KK-08 30.63 686.05 948 54 17.56 54 0.98 0.98 0.76 0.00 -0.98
399 69419 Santa Clara Cupertino Union Elementary KK-08 27.48 686.70 15228 709 21.48 709 0.00 0.00 0.00 0.00 0.00
400 69781 Santa Cruz Pacific Elementary KK-06 30.84 687.55 81 5 16.20 5 1.00 1.00 1.00 0.00 -1.00
401 69526 Santa Clara Los Gatos Union Elementary KK-08 34.16 689.10 2768 141 19.63 141 0.30 0.30 0.19 0.00 -0.30
402 69252 Santa Barbara Montecito Union Elementary KK-06 43.23 691.05 535 31 17.26 31 1.00 1.00 1.00 0.00 -1.00
403 68387 San Diego Solana Beach Elementary KK-06 27.95 691.35 2542 146 17.41 146 0.21 0.20 0.11 0.00 -0.21
404 68965 San Mateo Menlo Park City Elementary KK-08 49.94 691.90 1940 112 17.32 112 0.37 0.37 0.26 0.00 -0.37
405 65425 Marin Reed Union Elementary KK-08 55.33 693.95 1059 65 16.29 65 0.74 0.74 0.55 0.00 -0.74
406 65391 Marin Mill Valley Elementary KK-08 35.48 694.25 2340 132 17.73 132 0.28 0.27 0.15 0.00 -0.28
407 61713 Contra Costa Lafayette Elementary KK-08 34.30 694.80 3469 172 20.17 172 0.19 0.19 0.09 0.00 -0.19
408 68056 San Diego Del Mar Union Elementary KK-06 38.63 695.20 2106 115 18.31 115 0.39 0.38 0.25 0.00 -0.39
409 69088 San Mateo Woodside Elementary KK-08 35.34 695.30 478 33 14.48 33 1.00 1.00 1.00 0.00 -1.00
410 61747 Contra Costa Moraga Elementary KK-08 31.05 696.55 1885 98 19.23 98 0.54 0.54 0.40 0.00 -0.54
411 61770 Contra Costa Orinda Union Elementary KK-08 40.26 698.20 2422 139 17.42 139 0.23 0.23 0.12 0.00 -0.23
412 68908 San Mateo Hillsborough City Elementary KK-08 35.81 698.25 1318 87 15.15 87 0.46 0.45 0.31 0.00 -0.46
413 69161 Santa Barbara Cold Spring Elementary KK-06 43.23 698.45 220 12 18.33 12 1.00 1.00 1.00 0.00 -1.00
414 68981 San Mateo Portola Valley Elementary KK-08 50.68 699.10 687 45 15.27 45 1.00 1.00 0.82 0.00 -1.00
415 69682 Santa Clara Saratoga Union Elementary KK-08 40.40 700.30 2341 124 18.88 124 0.36 0.35 0.23 0.00 -0.36
416 68957 San Mateo Las Lomitas Elementary KK-08 28.72 704.30 984 60 16.40 60 0.82 0.82 0.65 0.00 -0.82
417 69518 Santa Clara Los Altos Elementary KK-08 41.73 706.75 3724 208 17.90 208 0.02 0.02 0.00 0.00 -0.02
418 72611 Ventura Somis Union Elementary KK-08 23.73 645.00 441 20 22.05 20 1.00 1.00 1.00 0.30 -0.70
419 72744 Yuba Plumas Elementary KK-08 9.95 672.20 101 5 20.20 5 1.00 1.00 1.00 0.60 -0.40
420 72751 Yuba Wheatland Elementary KK-08 12.50 655.75 1778 93 19.12 93 0.58 0.58 0.49 0.00 -0.58

Allocation Distribution Analysis

Given the allocations we have, not

df <- df_alloc_i_long
vars.group <- c(svr_rho)
var.numeric <- 'F_i'
str.stats.group <- 'allperc'
ar.perc <- c(0.01, seq(0.05,0.95,by=0.05), 0.99)
ls_summ_by_group <- ff_summ_bygroup(df, vars.group, var.numeric, str.stats.group, ar.perc)
## Warning: attributes are not identical across measure variables;
## they will be dropped
df_table_grp_stats <- ls_summ_by_group$df_table_grp_stats
df_row_grp_stats <- ls_summ_by_group$df_row_grp_stats
df_overall_stats <- ls_summ_by_group$df_overall_stats
df_row_stats_all <- ls_summ_by_group$df_row_stats_all

# Display Results
kable(df_table_grp_stats) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
rho mean median sd IQR mad 1% 5% 10% 15% 20% 25% 30% 35% 40% 45% 50% 55% 60% 65% 70% 75% 80% 85% 90% 95% 99% min max first last n.distinct
1 0.6644575 1.0000000 0.4115397 0.7179677 0.0000000 0 0 0 0 0.0998987 0.2820323 0.3687255 0.5187456 0.6579938 0.8899628 1.0000000 1.0000000 1.000000 1.000000 1.0000000 1.0000000 1 1 1 1 1 0 1 0 1 129
2 0.6644280 1.0000000 0.4115730 0.7252964 0.0000000 0 0 0 0 0.1008511 0.2747036 0.3687255 0.5171341 0.6512522 0.8897341 1.0000000 1.0000000 1.000000 1.000000 1.0000000 1.0000000 1 1 1 1 1 0 1 0 1 127
3 0.6602796 1.0000000 0.4113041 0.7764363 0.0000000 0 0 0 0 0.0952004 0.2235637 0.3663236 0.5174757 0.6490476 0.8269231 1.0000000 1.0000000 1.000000 1.000000 1.0000000 1.0000000 1 1 1 1 1 0 1 0 1 137
4 0.3334399 0.0236926 0.4153469 0.7541667 0.0351266 0 0 0 0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0236926 0.1362247 0.266876 0.398797 0.5480832 0.7541667 1 1 1 1 1 0 1 0 1 105

DF4b: Roster Cumulative Optimal Allocations (df_alloc_il)

Generate the df_alloc_il_long file.

Single Rho

# Parameters
svr_id_i <- 'id_i'
svr_id_t <- svr_inpalc
st_idcol_prefix <- 'sid_'

# Invoke Function
ls_df_rosterwide <- ff_panel_expand_longrosterwide(
  df_queue_il_long %>% filter(rho == 1) %>%
    select(one_of(svr_id_i, svr_id_t)),
  svr_id_t, svr_id_i, st_idcol_prefix)

# Get Ouputs
df_roster_wide_func <- ls_df_rosterwide$df_roster_wide
df_roster_wide_cumu_func <- ls_df_rosterwide$df_roster_wide_cumu

# Print Results
print(head(df_roster_wide_func,30))
## # A tibble: 30 x 421
##     Q_il sid_1 sid_2 sid_3 sid_4 sid_5 sid_6 sid_7 sid_8 sid_9 sid_10 sid_11
##    <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
##  1     1    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  2     2    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  3     3    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  4     4    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  5     5    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  6     6    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  7     7    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
##  8     8    NA    NA    NA    NA    NA     1    NA    NA    NA     NA     NA
##  9     9    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
## 10    10    NA    NA    NA    NA    NA    NA    NA    NA    NA     NA     NA
## # ... with 20 more rows, and 409 more variables: sid_12 <dbl>, sid_13 <dbl>,
## #   sid_14 <dbl>, sid_15 <dbl>, sid_16 <dbl>, sid_17 <dbl>, sid_18 <dbl>,
## #   sid_19 <dbl>, sid_20 <dbl>, sid_21 <dbl>, sid_22 <dbl>, sid_23 <dbl>,
## #   sid_24 <dbl>, sid_25 <dbl>, sid_26 <dbl>, sid_27 <dbl>, sid_28 <dbl>,
## #   sid_29 <dbl>, sid_30 <dbl>, sid_31 <dbl>, sid_32 <dbl>, sid_33 <dbl>,
## #   sid_34 <dbl>, sid_35 <dbl>, sid_36 <dbl>, sid_37 <dbl>, sid_38 <dbl>,
## #   sid_39 <dbl>, sid_40 <dbl>, sid_41 <dbl>, sid_42 <dbl>, sid_43 <dbl>, ...
print(head(df_roster_wide_cumu_func,30))
## # A tibble: 30 x 421
##     Q_il sid_1 sid_2 sid_3 sid_4 sid_5 sid_6 sid_7 sid_8 sid_9 sid_10 sid_11
##    <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
##  1     1     0     0     0     0     0     0     0     0     0      0      0
##  2     2     0     0     0     0     0     0     0     0     0      0      0
##  3     3     0     0     0     0     0     0     0     0     0      0      0
##  4     4     0     0     0     0     0     0     0     0     0      0      0
##  5     5     0     0     0     0     0     0     0     0     0      0      0
##  6     6     0     0     0     0     0     0     0     0     0      0      0
##  7     7     0     0     0     0     0     0     0     0     0      0      0
##  8     8     0     0     0     0     0     1     0     0     0      0      0
##  9     9     0     0     0     0     0     1     0     0     0      0      0
## 10    10     0     0     0     0     0     1     0     0     0      0      0
## # ... with 20 more rows, and 409 more variables: sid_12 <dbl>, sid_13 <dbl>,
## #   sid_14 <dbl>, sid_15 <dbl>, sid_16 <dbl>, sid_17 <dbl>, sid_18 <dbl>,
## #   sid_19 <dbl>, sid_20 <dbl>, sid_21 <dbl>, sid_22 <dbl>, sid_23 <dbl>,
## #   sid_24 <dbl>, sid_25 <dbl>, sid_26 <dbl>, sid_27 <dbl>, sid_28 <dbl>,
## #   sid_29 <dbl>, sid_30 <dbl>, sid_31 <dbl>, sid_32 <dbl>, sid_33 <dbl>,
## #   sid_34 <dbl>, sid_35 <dbl>, sid_36 <dbl>, sid_37 <dbl>, sid_38 <dbl>,
## #   sid_39 <dbl>, sid_40 <dbl>, sid_41 <dbl>, sid_42 <dbl>, sid_43 <dbl>, ...

Multiple Rhos

use do anything to solve for multiple rhos and stack.

# Parameters
svr_id_i <- 'id_i'
svr_id_t <- svr_inpalc
st_idcol_prefix <- 'sid_'

# Invoke Function
df_alloc_il <- df_queue_il_long %>%
  select(one_of('rho', svr_id_i, svr_id_t)) %>%
  group_by(rho) %>%
  do(alloc_i_upto_Q =
       ff_panel_expand_longrosterwide(df=.,
                                      svr_id_t=svr_id_t,
                                      svr_id_i=svr_id_i,
                                      st_idcol_prefix=st_idcol_prefix)$df_roster_wide_cumu) %>%
  unnest() %>% select(-one_of(paste0('rho', '1')))
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(alloc_i_upto_Q)`
# Print Results
print(head(df_alloc_il,30))
## # A tibble: 30 x 422
##      rho  Q_il sid_1 sid_2 sid_3 sid_4 sid_5 sid_6 sid_7 sid_8 sid_9 sid_10
##    <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
##  1     1     1     0     0     0     0     0     0     0     0     0      0
##  2     1     2     0     0     0     0     0     0     0     0     0      0
##  3     1     3     0     0     0     0     0     0     0     0     0      0
##  4     1     4     0     0     0     0     0     0     0     0     0      0
##  5     1     5     0     0     0     0     0     0     0     0     0      0
##  6     1     6     0     0     0     0     0     0     0     0     0      0
##  7     1     7     0     0     0     0     0     0     0     0     0      0
##  8     1     8     0     0     0     0     0     1     0     0     0      0
##  9     1     9     0     0     0     0     0     1     0     0     0      0
## 10     1    10     0     0     0     0     0     1     0     0     0      0
## # ... with 20 more rows, and 410 more variables: sid_11 <dbl>, sid_12 <dbl>,
## #   sid_13 <dbl>, sid_14 <dbl>, sid_15 <dbl>, sid_16 <dbl>, sid_17 <dbl>,
## #   sid_18 <dbl>, sid_19 <dbl>, sid_20 <dbl>, sid_21 <dbl>, sid_22 <dbl>,
## #   sid_23 <dbl>, sid_24 <dbl>, sid_25 <dbl>, sid_26 <dbl>, sid_27 <dbl>,
## #   sid_28 <dbl>, sid_29 <dbl>, sid_30 <dbl>, sid_31 <dbl>, sid_32 <dbl>,
## #   sid_33 <dbl>, sid_34 <dbl>, sid_35 <dbl>, sid_36 <dbl>, sid_37 <dbl>,
## #   sid_38 <dbl>, sid_39 <dbl>, sid_40 <dbl>, sid_41 <dbl>, sid_42 <dbl>, ...

DF3 and DF4 Functionalize

Solve optimal allocation problem over many rhos. Take the results from the Previous Two Sections, and generate a function

Take as input df_input_il, and optionally df_input_ib

Optimal Queue Solution Function

Generate function. Organize parameters not by i or il specific parameters, but by parameter types:

  1. input arrays and scalars
  2. input dataframe
  3. rho variable
  4. ids
  5. feasible allocations
  6. optimal queues
  7. i and l specific information
ffi_solve_queue <- function(ar_rho,
                            fl_teacher_increase_number,
                            df_input_il,
                            svr_rho = 'rho',
                            svr_id_i = 'id_i', svr_id_il = 'id_il',
                            svr_D_max_i = 'D_max_i', svr_D_il = 'D_il',
                            svr_inpalc = 'Q_il', svr_D_Wbin_il = 'D_Wbin_il',
                            svr_A_il = 'A_il', svr_alpha_il = 'alpha_il', svr_beta_i = 'beta_i',
                            svr_expout = 'opti_exp_outcome'){

    # Call function to Solve for Optimal Targeting Queue
    ls_df_queues <- ffp_opt_anlyz_rhgin_bin(df_input_il,
                                            svr_id_i = svr_id_il,
                                            svr_A_i = svr_A_il, svr_alpha_i = svr_alpha_il, svr_beta_i = svr_beta_i,
                                            ar_rho = ar_rho,
                                            svr_rho = svr_rho,
                                            svr_inpalc = svr_inpalc,
                                            svr_expout = svr_expout,
                                            verbose = FALSE)

    # Allocations that would be below resource threshold.
    df_queue_il_long <- ls_df_queues$df_all_rho_long %>%
      mutate(!!sym(svr_D_Wbin_il) :=
               case_when(!!sym(svr_inpalc) <= fl_teacher_increase_number ~ 1,
                         TRUE ~ 0)) %>%
      left_join(df_input_il %>%
                  select(!!sym(svr_id_i), !!sym(svr_id_il),
                         !!sym(svr_D_max_i), !!sym(svr_D_il)),
                by=svr_id_il) %>%
      select(!!sym(svr_rho),
             !!sym(svr_id_i), !!sym(svr_id_il),
             !!sym(svr_D_max_i), !!sym(svr_D_il),
             !!sym(svr_inpalc), !!sym(svr_D_Wbin_il),
             !!sym(svr_A_il), !!sym(svr_alpha_il), !!sym(svr_beta_i))

    # Results from optimal targeting
    # wide frame is mainly for visualization and analysis
    df_queue_il_wide <- ls_df_queues$df_all_rho

    return(list(df_queue_il_long=df_queue_il_long, df_queue_il_wide=df_queue_il_wide))
}

Test call Function.

# Function Test
ls_df_queue <- ffi_solve_queue(ar_rho, fl_teacher_increase_number, df_input_il)
## Joining, by = "id_il"
df_queue_il_long_func <- ls_df_queue$df_queue_il_long
df_queue_il_wide_func <- ls_df_queue$df_queue_il_wide

# Compare with Non-Function Inovke
# if 0 below, no difference
sum(df_queue_il_long$Q_il - df_queue_il_long_func$Q_il)
## [1] 0

Optimal Allocation Function

Generate function.

ffi_solve_alloc <- function(df_queue_il_long,
                            svr_rho = 'rho',
                            svr_id_i = 'id_i',
                            svr_D_max_i = 'D_max_i',
                            svr_D_star_i = 'D_star_i', svr_F_star_i = 'F_star_i',
                            svr_D_Wbin_il = 'D_Wbin_il'){

  # Individual total allocation given resource constraint and how many i allocation ranks are below resource
  # Both aggregate discrete level of allocation as well as allocation as a fraction of individual maximum

  df_alloc_i_long <- df_queue_il_long %>%
    select(!!sym(svr_rho), !!sym(svr_id_i),
           !!sym(svr_D_max_i), !!sym(svr_D_Wbin_il)) %>%
    group_by(!!sym(svr_id_i), !!sym(svr_rho)) %>%
    summarize(!!sym(svr_D_max_i)  := mean(!!sym(svr_D_max_i)),
              !!sym(svr_D_star_i) := sum(!!sym(svr_D_Wbin_il)),
              !!sym(svr_F_star_i) := (!!sym(svr_D_star_i)/!!sym(svr_D_max_i))) %>%
    mutate(!!sym(svr_rho) := as.numeric(!!sym(svr_rho))) %>%
    arrange(!!sym(svr_id_i), !!sym(svr_rho))

    return(df_alloc_i_long)
}

Test call Function.

# Function Test
df_alloc_i_long_func <- ffi_solve_alloc(df_queue_il_long_func)
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
# Compare with Non-Function Inovke
# if 0 below, no difference
sum(df_alloc_i_long$D_star_i - df_alloc_i_long_func$D_star_i)
## [1] 0

Given df_queue_il generate df_value_il

This is not tested line by line earlier, but tested line by line in the REV section later.

# value given optimal choices up to Q=W point.
ffi_disc_value_star_q <- function(fl_rho, df_queue_il,
                                  bl_return_allQ_V = FALSE,
                                  bl_return_inner_V = FALSE,
                                  svr_id_i = 'id_i',
                                  svr_D_il = 'D_il', svr_inpalc = 'Q_il', svr_D_Wbin_il = 'D_Wbin_il',
                                  svr_A_il = 'A_il', svr_alpha_il = 'alpha_il', svr_beta_i = 'beta_i',
                                  svr_V_cumu_l = 'V_sum_l',
                                  svr_V_inner_Q_il = 'V_inner_Q_il',
                                  svr_V_star_Q_il = 'V_star_Q_il'){

  if(length(fl_rho)>1){
    # rho could be fed in an an array, with all identical values
    fl_rho <- fl_rho[1]
  }

  # A.1 Di=0 Utility for all
  df_rev_dizr_i_onerho <- df_queue_il %>%
      filter(!!sym(svr_D_il) == 1) %>%
      select(!!sym(svr_id_i), !!sym(svr_beta_i), !!sym(svr_A_il)) %>%
      mutate(!!sym(svr_V_cumu_l) := !!sym(svr_beta_i)*((!!sym(svr_A_il))^fl_rho),
             !!sym(svr_inpalc) := 0) %>%
      select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))

  # A.2 Cumulative Within Person Utility Inner Power Di, only D_Wbin_il == 1, those within allocaiton bound
  if (bl_return_allQ_V) {
    df_rev_il_long_onerho <- df_queue_il
  } else {
    # only evaluate up to resource
    df_rev_il_long_onerho <- df_queue_il %>% filter(!!sym(svr_D_Wbin_il) == 1)
  }
  df_rev_il_long_onerho <- df_rev_il_long_onerho %>%
                              mutate(!!sym(svr_V_cumu_l) :=
                                       !!sym(svr_beta_i)*((!!sym(svr_A_il)+!!sym(svr_alpha_il))^fl_rho)) %>%
                              select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))

  # A.3 Run cum sum function
  df_rev_il_long_onerho <- rbind(df_rev_dizr_i_onerho, df_rev_il_long_onerho)
  df_rev_il_long_onerho <- df_rev_il_long_onerho %>%
                              select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
  df_rev_il_long_onerho <- ff_panel_cumsum_grouplast(df_rev_il_long_onerho,
                                                     svr_id=svr_id_i, svr_x=svr_inpalc, svr_y=svr_V_cumu_l,
                                                     svr_cumsumtop = svr_V_inner_Q_il,
                                                     stat='sum', quick=TRUE)

  # A.4 Outter power
  # Exclude Rank = 0, already used them to calculate total cumulative
  df_rev_il_long_onerho <- df_rev_il_long_onerho %>% filter(!!sym(svr_inpalc) != 0)
  df_rev_Ail_onerho <- df_rev_il_long_onerho %>%
    mutate(!!sym(svr_V_star_Q_il) := (!!sym(svr_V_inner_Q_il))^(1/fl_rho))


  # Export: function is given rho, so no rho to export
  svr_return_vars <- c(svr_inpalc, svr_V_star_Q_il)
  if (bl_return_inner_V) {
    svr_return_vars <- c(svr_inpalc, svr_V_cumu_l, svr_V_inner_Q_il, svr_V_star_Q_il)
  }
  df_rev_Ail_onerho <- df_rev_Ail_onerho %>% select(one_of(svr_return_vars))

  # Return
  return(df_rev_Ail_onerho)
}

Optimal Queue and Allocation Joint Function

Generate function. Organize parameters not by i or il specific parameters, but by parameter types:

  1. input arrays and scalars: ar_rho, fl_teacher_increase_number
  2. input dataframe: df_input_il
  3. rho variable: svr_rho
  4. ids: svr_id_i and svr_id_il
  5. feasible allocations: svr_D_max_i, svr_D_il
  6. optimal allocations (based on queue): D_star_i, svr_F_star_i
  7. optimal queues: svr_inpalc, svr_D_Wbin_il
  8. i and l specific information: \(A_{il}\), \(\alpha_{il}\), \(\beta_{i}\)
ffi_solve_queue_alloc <- function(ar_rho,
                                  fl_teacher_increase_number,
                                  df_input_il,
                                  bl_return_V = TRUE,
                                  bl_return_allQ_V = FALSE,
                                  bl_return_inner_V = FALSE,
                                  svr_rho = 'rho', svr_rho_val = 'rho_val',
                                  svr_id_i = 'id_i', svr_id_il = 'id_il',
                                  svr_D_max_i = 'D_max_i', svr_D_il = 'D_il',
                                  svr_D_star_i = 'D_star_i', svr_F_star_i = 'F_star_i', svr_EH_star_i = 'EH_star_i',
                                  svr_inpalc = 'Q_il', svr_D_Wbin_il = 'D_Wbin_il',
                                  svr_A_il = 'A_il', svr_alpha_il = 'alpha_il', svr_beta_i = 'beta_i',
                                  svr_expout = 'opti_exp_outcome',
                                  svr_V_star_Q_il = 'V_star_Q_il'){

    # Step 1
    # Call function to Solve for Optimal Targeting Queue
    ls_df_queues <- ffp_opt_anlyz_rhgin_bin(df_input_il,
                                            svr_id_i = svr_id_il,
                                            svr_A_i = svr_A_il, svr_alpha_i = svr_alpha_il, svr_beta_i = svr_beta_i,
                                            ar_rho = ar_rho, svr_rho_val = svr_rho_val,
                                            svr_rho = svr_rho,
                                            svr_inpalc = svr_inpalc,
                                            svr_expout = svr_expout,
                                            verbose = FALSE)
    df_queue_il_long <- ls_df_queues$df_all_rho_long
    df_queue_il_wide <- ls_df_queues$df_all_rho

    # Step 2
    # Allocations that would be below resource threshold.
    df_queue_il_long <- df_queue_il_long %>%
      mutate(!!sym(svr_D_Wbin_il) :=
               case_when(!!sym(svr_inpalc) <= fl_teacher_increase_number ~ 1,
                         TRUE ~ 0)) %>%
      left_join(df_input_il %>%
                  select(!!sym(svr_id_i), !!sym(svr_id_il),
                         !!sym(svr_D_max_i), !!sym(svr_D_il)),
                by=svr_id_il)

    # Step 3
    # Optimal Allocation Discrete Levels
    df_alloc_i_long <- df_queue_il_long %>%
      select(!!sym(svr_rho), !!sym(svr_rho_val), !!sym(svr_id_i),
             !!sym(svr_D_max_i), !!sym(svr_D_Wbin_il)) %>%
      group_by(!!sym(svr_id_i), !!sym(svr_rho)) %>%
      summarize(!!sym(svr_rho_val)  := mean(!!sym(svr_rho_val)),
                !!sym(svr_D_max_i)  := mean(!!sym(svr_D_max_i)),
                !!sym(svr_D_star_i) := sum(!!sym(svr_D_Wbin_il)),
                !!sym(svr_F_star_i) := (!!sym(svr_D_star_i)/!!sym(svr_D_max_i))) %>%
      arrange(!!sym(svr_id_i), !!sym(svr_rho))

    # Step 4
    # Expected Outcome Given Optimal Choices
    # df_alloc_i_long -> left_join(df_input_il) -> Generate EH
    # Very straight forward, except need to deal with D_star_i = 0, merge D_star_i and di jointly
    df_alloc_i_long <- df_alloc_i_long %>%
      mutate(D_star_i_zr1 =
               case_when(!!sym(svr_D_star_i) == 0 ~ 1, # for merging where D_star = 0
                         TRUE ~ !!sym(svr_D_star_i))) %>%
      left_join(df_input_il %>%
                  select(!!sym(svr_id_i), !!sym(svr_D_il),
                         !!sym(svr_A_il), !!sym(svr_alpha_il)),
                by=setNames(c(svr_id_i, svr_D_il), c(svr_id_i, 'D_star_i_zr1'))) %>%
      mutate(!!sym(svr_EH_star_i) :=
               case_when(!!sym(svr_D_star_i) == 0 ~ !!sym(svr_A_il), # no choice no allocation
                         TRUE ~ !!sym(svr_A_il) + !!sym(svr_alpha_il)))

    # Step 5a, value at Q points
    svr_return_list <- c(svr_rho, svr_rho_val, svr_id_i, svr_id_il,
                         svr_D_max_i, svr_D_il, svr_inpalc, svr_D_Wbin_il)
    # svr_A_il, svr_alpha_il, svr_beta_i

    if (bl_return_V){
      mt_util_rev_loop <- df_queue_il_long %>%
        group_by(!!sym(svr_rho)) %>%
        do(rev = ffi_disc_value_star_q(fl_rho = .[[svr_rho_val]],
                                       df_queue_il = .,
                                       bl_return_allQ_V = bl_return_allQ_V,
                                       bl_return_inner_V = bl_return_inner_V,
                                       svr_id_i = svr_id_i,
                                       svr_D_il = svr_D_il, svr_inpalc = svr_inpalc, svr_D_Wbin_il = svr_D_Wbin_il,
                                       svr_A_il = svr_A_il, svr_alpha_il = svr_alpha_il, svr_beta_i = svr_beta_i,
                                       svr_V_star_Q_il = svr_V_star_Q_il)) %>%
            unnest()
      # Step 5b, merge values to queue df
      df_queue_il_long <- df_queue_il_long %>% left_join(mt_util_rev_loop,
                                     by=setNames(c(svr_rho, svr_inpalc), c(svr_rho, svr_inpalc))) %>%
                          select(one_of(svr_return_list), starts_with('V_'))
    } else {
      # Step 5c, no value return
      df_queue_il_long <- df_queue_il_long %>% select(one_of(svr_return_list))
    }

    # Step 6
    # Sort columns
    df_alloc_i_long <- df_alloc_i_long %>%
      select(!!sym(svr_rho), !!sym(svr_rho_val),
             !!sym(svr_id_i),
             !!sym(svr_D_max_i), !!sym(svr_D_star_i), !!sym(svr_F_star_i), !!sym(svr_EH_star_i))

    return(list(df_queue_il_long=df_queue_il_long,
                df_queue_il_wide=df_queue_il_wide,
                df_alloc_i_long=df_alloc_i_long))
}

Test call Function.

# Function Test
ls_df_queue_alloc <- ffi_solve_queue_alloc(ar_rho, fl_teacher_increase_number, df_input_il)
## Joining, by = "id_il"
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(rev)`
df_queue_il_long_func <- ls_df_queue_alloc$df_queue_il_long
df_queue_il_wide_func <- ls_df_queue_alloc$df_queue_il_wide
mt_util_rev_loop <- ls_df_queue_alloc$mt_util_rev_loop
df_alloc_i_long_func <- ls_df_queue_alloc$df_alloc_i_long

# Compare with Non-Function Inovke
# if 0 below, no difference
sum(df_queue_il_long$Q_il - df_queue_il_long_func$Q_il)
## [1] 0
sum(df_alloc_i_long$D_star_i - df_alloc_i_long_func$D_star_i)
## [1] 0

Test return with V or not, with inner V or not, solve up to all Q or not

# when bl_return_V = FALSE, other two don't matter
bl_return_V <- FALSE
head(ffi_solve_queue_alloc(ar_rho, fl_teacher_increase_number, df_input_il,
                           bl_return_V=bl_return_V)$df_queue_il_long, 10)
## Joining, by = "id_il"
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
## # A tibble: 10 x 8
##      rho rho_val  id_i id_il D_max_i  D_il  Q_il D_Wbin_il
##    <dbl>   <dbl> <int> <int>   <dbl> <int> <int>     <dbl>
##  1     1   0.99      1     1      11     1   138         1
##  2     2   0.785     1     1      11     1   140         1
##  3     3  -3.64      1     1      11     1   244         1
##  4     4 -99         1     1      11     1 36657         0
##  5     1   0.99      1     2      11     2   209         1
##  6     2   0.785     1     2      11     2   212         1
##  7     3  -3.64      1     2      11     2   372         1
##  8     4 -99         1     2      11     2 39093         0
##  9     1   0.99      1     3      11     3   297         1
## 10     2   0.785     1     3      11     3   305         1
# by default, no inner only up to resource
bl_return_V <- TRUE
head(ffi_solve_queue_alloc(ar_rho, fl_teacher_increase_number, df_input_il,
                           bl_return_V=bl_return_V)$df_queue_il_long, 10)
## Joining, by = "id_il"
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(rev)`
## # A tibble: 10 x 9
##      rho rho_val  id_i id_il D_max_i  D_il  Q_il D_Wbin_il V_star_Q_il
##    <dbl>   <dbl> <int> <int>   <dbl> <int> <dbl>     <dbl>       <dbl>
##  1     1   0.99      1     1      11     1   138         1        655.
##  2     2   0.785     1     1      11     1   140         1        655.
##  3     3  -3.64      1     1      11     1   244         1        654.
##  4     4 -99         1     1      11     1 36657         0         NA 
##  5     1   0.99      1     2      11     2   209         1        655.
##  6     2   0.785     1     2      11     2   212         1        655.
##  7     3  -3.64      1     2      11     2   372         1        654.
##  8     4 -99         1     2      11     2 39093         0         NA 
##  9     1   0.99      1     3      11     3   297         1        655.
## 10     2   0.785     1     3      11     3   305         1        655.
# by default, no inner only up to resource
bl_return_V <- TRUE
bl_return_inner_V <- TRUE
head(ffi_solve_queue_alloc(ar_rho, fl_teacher_increase_number, df_input_il,
                           bl_return_V=bl_return_V,
                           bl_return_inner_V=bl_return_inner_V)$df_queue_il_long, 10)
## Joining, by = "id_il"
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(rev)`
## # A tibble: 10 x 11
##      rho rho_val  id_i id_il D_max_i  D_il  Q_il D_Wbin_il   V_sum_l
##    <dbl>   <dbl> <int> <int>   <dbl> <int> <dbl>     <dbl>     <dbl>
##  1     1   0.99      1     1      11     1   138         1  1.54e+ 0
##  2     2   0.785     1     1      11     1   140         1  4.03e- 1
##  3     3  -3.64      1     1      11     1   244         1  1.08e-13
##  4     4 -99         1     1      11     1 36657         0 NA       
##  5     1   0.99      1     2      11     2   209         1  1.55e+ 0
##  6     2   0.785     1     2      11     2   212         1  4.03e- 1
##  7     3  -3.64      1     2      11     2   372         1  1.08e-13
##  8     4 -99         1     2      11     2 39093         0 NA       
##  9     1   0.99      1     3      11     3   297         1  1.55e+ 0
## 10     2   0.785     1     3      11     3   305         1  4.04e- 1
## # ... with 2 more variables: V_inner_Q_il <dbl>, V_star_Q_il <dbl>
# by default, inner values as well as all values even if D_Wbin_il = 0
# This takes much more time.
bl_return_V <- TRUE
bl_return_inner_V <- TRUE
bl_return_allQ_V <- TRUE
head(ffi_solve_queue_alloc(ar_rho, fl_teacher_increase_number, df_input_il,
                           bl_return_V=bl_return_V,
                           bl_return_inner_V=bl_return_inner_V,
                           bl_return_allQ_V=bl_return_allQ_V)$df_queue_il_long, 10)
## Joining, by = "id_il"
## `summarise()` has grouped output by 'id_i'. You can override using the `.groups` argument.
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(rev)`
## # A tibble: 10 x 11
##      rho rho_val  id_i id_il D_max_i  D_il  Q_il D_Wbin_il   V_sum_l
##    <dbl>   <dbl> <int> <int>   <dbl> <int> <dbl>     <dbl>     <dbl>
##  1     1   0.99      1     1      11     1   138         1 1.54e+  0
##  2     2   0.785     1     1      11     1   140         1 4.03e-  1
##  3     3  -3.64      1     1      11     1   244         1 1.08e- 13
##  4     4 -99         1     1      11     1 36657         0 1.59e-284
##  5     1   0.99      1     2      11     2   209         1 1.55e+  0
##  6     2   0.785     1     2      11     2   212         1 4.03e-  1
##  7     3  -3.64      1     2      11     2   372         1 1.08e- 13
##  8     4 -99         1     2      11     2 39093         0 1.36e-284
##  9     1   0.99      1     3      11     3   297         1 1.55e+  0
## 10     2   0.785     1     3      11     3   305         1 4.04e-  1
## # ... with 2 more variables: V_inner_Q_il <dbl>, V_star_Q_il <dbl>

DF5: Resource Equivalent Variations (df_rev_il)

For REV generate cumulative utility up to the ith individual’s lth allocation, cumulating over all individuals and allocations below the the current ilth rank.

  1. svr_V_cumu_l: utility summation within individual up to lth allocation, no outter power
    • \(\rho >0\): this is increasing in additional allocation
    • \(\rho <0\): this is decreasing in additional allocations
  2. svr_V_inner_Q_il: utility cumulative sum (inner sum), by ranking, across individuals, utility from all allocations up to the current rank, no outter power
    • \(\rho >0\): this is increasing in additional allocation
    • \(\rho <0\): this is decreasing in additional allocations
  3. svr_V_star_Q_il: utility cumulative, overall sum with outter power, outter power resets signs for both to positive
    • \(\rho >0\): this is increasing in additional allocation
    • \(\rho <0\): this is increasing in additional allocations
# Shared Names
svr_V_cumu_l <- 'V_sum_l'
svr_V_inner_Q_il <- 'V_inner_Q_il'
svr_V_star_Q_il <- 'V_star_Q_il'

Check Compare Total Resource Usages

Check the following:

  1. Total optimal allocation each rho, is resource constraint satisfied
  2. What would it mean to uniformly allocate across all individuals, total sum from uniform allocation
    • uniform addition for each school was already calculated
# Total optimal allocation each row, should equal to fl_teacher_increase_number
df_alloc_i_long %>%
  group_by(!!sym(svr_rho)) %>%
  summarize(sum_D_star_i = sum(D_star_i)) %>%
  mutate(summ_D_i_correct = case_when(fl_teacher_increase_number == sum_D_star_i ~ 1,
                                      TRUE ~ 0 ))
## # A tibble: 4 x 3
##     rho sum_D_star_i summ_D_i_correct
##   <dbl>        <dbl>            <dbl>
## 1     1        10840                1
## 2     2        10840                1
## 3     3        10840                1
## 4     4        10840                1
# What is the uniform allocation total
df_casch_prep_i %>% summarize(sum_D_o_i = sum(D_o_i))
##   sum_D_o_i
## 1     10841

df_rev_il_long based on df_input_il, this does include the REV number, but includes aggregate utility cumulative summed at each rank position point.

  1. \(\rho\)
  2. \(\text{ID}_{il}\): unique id for individual/allocation id
  3. \(Q_{il}\): allocation rank for the lth discrete allocation level for ith person.
  4. \(V_{il}\): aggregate utility up to the ith indiviudal lth allocation cumulative summing up to the rank

Resource Equivalent Variation, compare against evenly increasing allocation by the same percentage across all schools.

Testing Optimal Allocation One Rho

# Some fl_rho
it_rho_ctr <- 4
fl_rho <- ar_rho[it_rho_ctr]

Utility Uniform Allocation

Merge the data utility component dataframe with the random/uniform allocation frame. And simple sum for total utility.

  1. Select from main file id column and observed/unif/random allocation colummn
  2. Merge main left_join with utility component dataframe, only keep on row
  3. Simple Sum and Outter power form to generate overall utility from observed allocations
# Utility for Uniform Allocations
df_casch_prep_i_testlam <- df_input_ib %>% mutate(v_unif_i = beta_i*((A_i_l0+alpha_o_i)^fl_rho))
# view(df_casch_prep_i_testlam %>% select(id_i, v_unif_i, Omega_i, theta_i, D_o_i))
# Aggregate planner utility from uniform allocation
fl_util_unif_alloc_testlam <- df_casch_prep_i_testlam %>% summarize(v_sum_unif_i = sum(v_unif_i)^(1/fl_rho)) %>% pull()
# Print
cat('Utility from Uniform Allocation', '\n')
## Utility from Uniform Allocation
print(fl_util_unif_alloc_testlam)
## [1] 638.7197

Utility at Zero Allocation each i

Creating df_rev_Di0_i, i specific df. Long frame optimal queue data, additionally, also the raw dataframe with utility evaluated for each without additional allocations, given base allocations, no outter power.

# Step 1
# base no additional allocation utility, no outter power
# select D_il == 1, A_il here is utility without additional allocations
df_rev_Di0_i_onerho <- df_input_il %>%
                        filter(D_il == 1) %>%
                        select(id_i, beta_i, A_il) %>%
                        mutate(v_zero_i = beta_i*((A_il)^fl_rho))
# view(df_queue_il_long %>% filter(!!sym(svr_rho) == it_rho_ctr & id_i==1))
# view(df_rev_Di0_i_onerho %>% filter(id_i==1))
# view(df_queue_il_long %>% filter(!!sym(svr_rho) == it_rho_ctr) %>% mutate(v_zero_i = beta_i*((A_il)^fl_rho), v_A_plus_alpha_i = beta_i*((A_il+alpha_il)^fl_rho) ) %>% filter(id_i==1), title='onerho')

# Step 2: From the Util without allocation file generate id, rank and util_sumi_uptol columns.
df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% select(id_i, v_zero_i)

# Step 3
df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% mutate(!!sym(svr_inpalc) := 0)

# Step 4
df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>%
                        mutate(!!sym(svr_V_cumu_l) := v_zero_i) %>%
                        select(id_i, !!sym(svr_inpalc), !!sym(svr_V_cumu_l))

Utility Cumulative from Optimal Allocation

To build up overall value, calculate the utility contribution of school to overall functional form, at each increment of teacher. Just use the already generated A_il, alphia_il and beta_i.

  1. Consider Utility Calculations for both \(Z_{il}=1\) and \(Z_{il}=0\). Remember \(Z_{il}\) is \(0\) or \(1\), \(1\) is rank is below resource available. Do not need to compute utility for above resource availability. WHen summing, need to consider both \(0\) and \(1\). For \(1\), sum calculated by 2 and 3. FOr \(0\), count up schools not receiving allocations, and evaluate utility with allocation equal to zero, and sum up.
  2. Calculate util_cumu_i_uptol, individual component utility, including all allocations up to \(l\).
  3. Use ff_panel_cumsum_grouplast from REconTools to cumulative sum the util_cumu_i_uptol corresponding to the highest ranked position.

Note that df_rev_Ail dataframe is long, includes all rho results.

We want to compute utility at each ascending rank level. And find at which rank level utility from Optimal allocation equals to utility from uniform allocation.

  1. Utility at each rank, which is the sum of schools with additional allocations and without additioanl allocations
  2. Find the break even point
Utility for Schools with Additional Allocations

First, let’s do summation directly only based on df_queue_il_long, including schools that have nonzero allocations, ranking from first in queue for an additional teacher spot to last.

This is insufficient, because the cumulative sum will not include schools that have not received any additional allocations.

# Steps 1 and 2
df_rev_il_long_onerho_wrong <- df_queue_il_long %>%
                            filter(!!sym(svr_rho) == it_rho_ctr & D_Wbin_il == 1) %>%
                            mutate(!!sym(svr_V_cumu_l) :=  beta_i*((A_il+alpha_il)^fl_rho))

# Step 3, only for one rho
df_rev_il_long_onerho_wrong <- df_rev_il_long_onerho_wrong %>%
                        select(id_i, !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
df_rev_il_long_onerho_wrong <- ff_panel_cumsum_grouplast(df_rev_il_long_onerho_wrong,
                                               svr_id='id_i', svr_x=svr_inpalc, svr_y=svr_V_cumu_l,
                                               svr_cumsumtop = svr_V_inner_Q_il,
                                               stat='sum', quick=TRUE)

# Outter power
df_rev_il_long_onerho_wrong <- df_rev_il_long_onerho_wrong %>%
                        mutate(!!sym(svr_V_star_Q_il) :=
                                 (!!sym(svr_V_inner_Q_il))^(1/fl_rho))
Utility for Schools without and with Additional Allocations

But the above calculation is not fully sufficient, because we are not including into the utility evaluations at all schools that do not have any additional teacher allocation. Unlike in the binary case, where we could difference away and ignore individuals without allocations kind of, here we can not because the alternative is uniform allocation. So we need to consider, add up utility from all.

Can not simply reuse code from before, because need to compute this dynamically. starting with zero allocations.

  1. Below, grab the util with allocation zero values
  2. Set rank, which ff_panel_cumsum_grouplast will sort by, to zero, for when allocations are zero, other allocation rank smallest value is 1.
  3. Rename util_alloc_zero to have the same name as utility no outter power column in df_rev_Ail_long
  4. Stack base no alloc and opti queue files
# Same steps as above
df_rev_il_long_onerho <- df_queue_il_long %>%
                            filter(!!sym(svr_rho) == it_rho_ctr & D_Wbin_il == 1) %>%
                            mutate(!!sym(svr_V_cumu_l) := beta_i*((A_il+alpha_il)^fl_rho)) %>%
                            select(id_i, !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
# Now combine dataframes
df_rev_il_long_onerho <- rbind(df_rev_Di0_i_onerho, df_rev_il_long_onerho)
# view(df_rev_il_long_onerho %>% filter(id_i==1) %>% arrange(!!sym(svr_V_cumu_l)))

# TEST monotinicity
rank_max_min_val <- df_rev_il_long_onerho %>%
  arrange(id_i, !!sym(svr_inpalc)) %>% group_by(id_i) %>%
  mutate(util_sumi_uptol_min = min(abs(!!sym(svr_V_cumu_l)))) %>%
  filter(util_sumi_uptol_min == abs(!!sym(svr_V_cumu_l))) %>%
  ungroup() %>%
  summarize(rank_max = max(!!sym(svr_inpalc))) %>% pull()
if (rank_max_min_val != 0 & rank_max_min_val != fl_teacher_increase_number){
  # rank_max_min_val = 0 if rho > 0
  # rank_max_min_val = fl_teacher_increase_number if rho < 0
  stop('Fatal Error D_il = 0, inner power indi util abs value not smallest')
}

# Run cum sum function
df_rev_il_long_onerho <- df_rev_il_long_onerho %>%
                            select(id_i, !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
df_rev_il_long_onerho <- ff_panel_cumsum_grouplast(df_rev_il_long_onerho,
                                                   svr_id='id_i', svr_x=svr_inpalc, svr_y=svr_V_cumu_l,
                                                   svr_cumsumtop = svr_V_inner_Q_il,
                                                   stat='sum', quick=TRUE)

# Drop rank zero where utility order could look strange
# The results are a little bit strange looking, but correct
# if rho < 0, at rank = 0, adding up components of inner sum, V_inner_Q_il at first increasing adding through all rank = 0
# but after reach rank = 1, V_inner_Q_il starts decreasing, because each incremental allocation with rho<0 power has lower
# value compared to less allocation. When generating outter power rank = 0 when sorted is at first decreasing, then increasing
# after reach rank = 1, do not need to keep rank =0, drop them after cumsum, needed only for proper cumsum calculations.
df_rev_il_long_onerho <- df_rev_il_long_onerho %>% filter(!!sym(svr_inpalc) != 0)
# view(df_rev_il_long_onerho %>% filter(id_i==1) %>% arrange(!!sym(svr_V_cumu_l)))

# Outter power
df_rev_Ail_onerho <- df_rev_il_long_onerho %>%
  mutate(!!sym(svr_V_star_Q_il) := (!!sym(svr_V_inner_Q_il))^(1/fl_rho))
# view(df_rev_Ail_onerho %>% filter(id_i==1) %>% arrange(!!sym(svr_V_cumu_l)))
# view(df_rev_Ail_onerho %>% arrange(Q_il))
Compute REV

Now, given the current utility given optimal allocation with a particular preference, we can find REV. We simply look for the level of allocation needed (which \(Q_{il}\)) point where the corresponding \(V\) utility level equals the utility form uniform allocation.

# Note column !!sym(svr_V_star_Q_il) by construction is sorted and increasing
# if it is not sorted an increasing big problem.
it_w_exp_min <- min(df_rev_Ail_onerho %>% filter(!!sym(svr_V_star_Q_il) >= fl_util_unif_alloc_testlam) %>%
  pull(!!sym(svr_inpalc)))
fl_REV <- 1 - (it_w_exp_min/fl_teacher_increase_number)
# Print
print(paste0('fl_REV:', fl_REV))
## [1] "fl_REV:0.949261992619926"

Testing Optimal Allocation Multple Rhos

Implement the single rho algorithm above, but now for multpile rhos.

Utility Uniform Allocation

# Alternative Allocation Utility across rho (rho)
# both df_input_ib, fl_rho are first tier inputs
# Assume that column names conform
# ffi_disc_v_alt: function, discrete, value, alternative
ffi_disc_v_alt <- function(fl_rho, df_input_ib,
                           svr_A_i_l0 = 'A_i_l0',
                           svr_alpha_o_i = 'alpha_o_i',
                           svr_beta_i = 'beta_i'){

    fl_util_alter_alloc <- df_input_ib %>%
      mutate(v_unif_i = !!sym(svr_beta_i)*((!!sym(svr_A_i_l0) + !!sym(svr_alpha_o_i))^fl_rho)) %>%
      summarize(v_sum_unif_i = sum(v_unif_i)^(1/fl_rho)) %>%
      pull()

    return(fl_util_alter_alloc)
}

Test loop vs sapply invoke, they produce the same results.

# Loop Results
ar_util_unif_alloc_loop <- rep(NA, length(ar_rho))
for (it_rho_ctr in seq(1:length(ar_rho))) {
  fl_rho <- ar_rho[it_rho_ctr]
  ar_util_unif_alloc_loop[it_rho_ctr] <- ffi_disc_v_alt(fl_rho=fl_rho, df_input_ib=df_input_ib)
}

# Sapply Results
ar_util_unif_alloc_sapply <- sapply(ar_rho, ffi_disc_v_alt, df_input_ib=df_input_ib)

# Print
cat('ar_util_unif_alloc_loop:', ar_util_unif_alloc_loop,'\n')
## ar_util_unif_alloc_loop: 656.9924 656.9463 655.9468 638.7197
cat('ar_util_unif_alloc_sapply:', ar_util_unif_alloc_sapply,'\n')
## ar_util_unif_alloc_sapply: 656.9924 656.9463 655.9468 638.7197
cat(ar_util_unif_alloc_loop-ar_util_unif_alloc_sapply,'\n')
## 0 0 0 0

Utility at Zero Allocation for each \(i\)

Given \(\rho\), what is utility without additional allocations, not cumulative summed across individuals, only within individual inner power sum.

# ffi_disc_di0_onerho: function, discrete, allocation D_i = 0, one rho (rho)
# Note that input could be either df_input_il or df_queue_il, df_queue_il inherits the following variables from df_input_il
ffi_disc_dizr_onerho <- function(fl_rho, df_input_il,
                                 svr_id_i = 'id_i',
                                 svr_D_il = 'D_il',
                                 svr_inpalc = 'Q_il',
                                 svr_A_il = 'A_il',
                                 svr_beta_i = 'beta_i',
                                 svr_V_cumu_l = 'V_sum_l'){

    # print(fl_rho)
    # print('S1')
    # df_rev_Di0_i_onerho <- df_input_il %>% filter(!!sym(svr_D_il) == 1)
    # print(str(df_rev_Di0_i_onerho))
    #
    # print('S2')
    # df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% select(!!sym(svr_id_i), !!sym(svr_beta_i), !!sym(svr_A_il))
    # print(str(df_rev_Di0_i_onerho))
    #
    # print('S3')
    # df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% mutate(!!sym(svr_V_cumu_l) := !!sym(svr_beta_i)*((!!sym(svr_A_il))^fl_rho))
    # print(str(df_rev_Di0_i_onerho))
    #
    # print('S4')
    # df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% mutate(!!sym(svr_inpalc) := 0)
    # print(str(df_rev_Di0_i_onerho))
    #
    # print('S5')
    # df_rev_Di0_i_onerho <- df_rev_Di0_i_onerho %>% select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
    # print(str(df_rev_Di0_i_onerho))

    df_rev_Di0_i_onerho <- df_input_il %>%
      filter(!!sym(svr_D_il) == 1) %>%
      select(!!sym(svr_id_i), !!sym(svr_beta_i), !!sym(svr_A_il)) %>%
      mutate(!!sym(svr_V_cumu_l) := !!sym(svr_beta_i)*((!!sym(svr_A_il))^fl_rho),
             !!sym(svr_inpalc) := 0) %>%
      select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))

    return(df_rev_Di0_i_onerho)
}

Test loop vs sapply results.

# Loop Results
ls_util_di0_loop <- vector(mode = "list", length = length(ar_rho))
for (it_rho_ctr in seq(1:length(ar_rho))) {
  fl_rho <- ar_rho[it_rho_ctr]
  ls_util_di0_loop[[it_rho_ctr]] <- ffi_disc_dizr_onerho(fl_rho=fl_rho, df_input_il=df_input_il)
}

# Sapply Results
ls_util_di0_sapply <- sapply(ar_rho, ffi_disc_dizr_onerho, df_input_il=df_input_il)

# Compare and Print
print('ls_util_di0_loop[[1]][[3]][111]')
## [1] "ls_util_di0_loop[[1]][[3]][111]"
print(ls_util_di0_loop[[1]][[3]][111])
## [1] 1.412458
print('ls_util_di0_sapply[[3,1]][111]')
## [1] "ls_util_di0_sapply[[3,1]][111]"
print(ls_util_di0_sapply[[3,1]][111])
## [1] 1.412458
ls_util_di0_loop[[1]][[3]][1] - ls_util_di0_sapply[[3,1]][1]
## [1] 0
ls_util_di0_loop[[1]][[3]][111] - ls_util_di0_sapply[[3,1]][111]
## [1] 0

Utility Cumulative from Optimal Allocation

Calls the function just created ffi_disc_Di0_onerho, and callas the REconTools Function ff_panel_cumsum_grouplast.

The function below generates a new cumulative aggregate Utility at each allocation availability.

# ffi_disc_Diall_onerho: function, discrete, allocation D_i_all = 1 to D_max, all, one rho (rho)
# This function invokes two functions, project function ffi_disc_Di0_onerho, and REconTools Function ff_panel_cumsum_grouplast.
# df_queue_il is obtained from df_queue_il_long, for only one rho
# Note that svr_V_cumu_l, svr_V_inner_Q_il, svr_V_star_Q_il are generated by function, all other are input variables
ffi_disc_diall_onerho <- function(fl_rho, df_queue_il,
                                  svr_id_i = 'id_i',
                                  svr_D_il = 'D_il', svr_inpalc = 'Q_il', svr_D_Wbin_il = 'D_Wbin_il',
                                  svr_A_il = 'A_il', svr_alpha_il = 'alpha_il', svr_beta_i = 'beta_i',
                                  svr_V_cumu_l = 'V_sum_l',
                                  svr_V_inner_Q_il = 'V_inner_Q_il',
                                  svr_V_star_Q_il = 'V_star_Q_il'){

  # A. Di=0 Utility for all
  df_rev_dizr_i_onerho <- ffi_disc_dizr_onerho(fl_rho, df_queue_il, svr_id_i, svr_D_il, svr_inpalc,
                                               svr_A_il, svr_beta_i, svr_V_cumu_l)

  # B. Cumulative Within Person Utility Inner Power Di, only D_Wbin_il == 1, those within allocaiton bound
  df_rev_il_long_onerho <- df_queue_il %>%
                              filter(!!sym(svr_D_Wbin_il) == 1) %>%
                              mutate(!!sym(svr_V_cumu_l) :=
                                       !!sym(svr_beta_i)*((!!sym(svr_A_il)+!!sym(svr_alpha_il))^fl_rho)) %>%
                              select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))

  # C. Run cum sum function
  df_rev_il_long_onerho <- rbind(df_rev_dizr_i_onerho, df_rev_il_long_onerho)
  df_rev_il_long_onerho <- df_rev_il_long_onerho %>%
                              select(!!sym(svr_id_i), !!sym(svr_inpalc), !!sym(svr_V_cumu_l))
  df_rev_il_long_onerho <- ff_panel_cumsum_grouplast(df_rev_il_long_onerho,
                                                     svr_id=svr_id_i, svr_x=svr_inpalc, svr_y=svr_V_cumu_l,
                                                     svr_cumsumtop = svr_V_inner_Q_il,
                                                     stat='sum', quick=TRUE)

  # C. Outter power
  # Exclude Rank = 0, already used them to calculate total cumulative
  df_rev_il_long_onerho <- df_rev_il_long_onerho %>% filter(!!sym(svr_inpalc) != 0)
  df_rev_Ail_onerho <- df_rev_il_long_onerho %>%
    mutate(!!sym(svr_V_star_Q_il) := (!!sym(svr_V_inner_Q_il))^(1/fl_rho))

  # Return
  return(df_rev_Ail_onerho)
}

Test loop vs sapply results.

# Loop Results
ls_util_diall_loop <- vector(mode = "list", length = length(ar_rho))
for (it_rho_ctr in seq(1:length(ar_rho))) {
  fl_rho <- ar_rho[it_rho_ctr]
  df_queue_il_long_onerho <- df_queue_il_long %>% filter(!!sym(svr_rho) == it_rho_ctr)
  ls_util_diall_loop[[it_rho_ctr]] <- ffi_disc_diall_onerho(fl_rho=fl_rho, df_queue_il = df_queue_il_long_onerho)
}

# Sapply Results
df_queue_il_long_onerho <- df_queue_il_long %>% filter(!!sym(svr_rho) == 2)
ls_util_diall_sapply <- sapply(ar_rho, ffi_disc_diall_onerho, df_queue_il=df_queue_il_long_onerho)

# Compare and Print
print('ls_util_diall_loop[[2]][[\'v_sum_l\']][1]')
## [1] "ls_util_diall_loop[[2]][['v_sum_l']][1]"
print(ls_util_diall_loop[[2]][['V_sum_l']][1])
## [1] 0.3874141
print('ls_util_diall_sapply[[\'v_sum_l\',2]][1]')
## [1] "ls_util_diall_sapply[['v_sum_l',2]][1]"
print(ls_util_diall_sapply[['V_sum_l',2]][1])
## [1] 0.3874141
ls_util_diall_loop[[2]][['V_sum_l']][1] - ls_util_diall_sapply[['V_sum_l',2]][1]
## [1] 0
ls_util_diall_loop[[2]][['V_sum_l']][111] - ls_util_diall_sapply[['V_sum_l',2]][111]
## [1] 0

Utility Alternative and Optimal Comparison, Compute REV

Resource Equivalent Variations.

# ffi_disc_Diall_onerho: function, discrete, allocation D_i = 1 to D_max, one rho (rho)
# This function invokes two functions, project function ffi_disc_Di0_onerho, and REconTools Function ff_panel_cumsum_grouplast.
ffi_disc_rev_onerho_test <- function(fl_rho,
                                fl_teacher_increase_number,
                                df_input_ib, df_queue_il,
                                svr_A_i_l0 = 'A_i_l0', svr_alpha_o_i = 'alpha_o_i',
                                svr_id_i = 'id_i',
                                svr_D_il = 'D_il', svr_inpalc = 'Q_il', svr_D_Wbin_il = 'D_Wbin_il',
                                svr_A_il = 'A_il', svr_alpha_il = 'alpha_il', svr_beta_i = 'beta_i',
                                svr_V_cumu_l = 'V_sum_l',
                                svr_V_inner_Q_il = 'V_inner_Q_il',
                                svr_V_star_Q_il = 'V_star_Q_il'){

  if(length(fl_rho)>1){
    # rho could be fed in an an array, with all identical values
    fl_rho <- fl_rho[1]
  }

  # A. Cumulative Aggregate Utility at Each Individual Allocation Rank
  df_rev_Ail_onerho <- ffi_disc_diall_onerho(fl_rho, df_queue_il,
                                             svr_id_i, svr_D_il, svr_inpalc, svr_D_Wbin_il,
                                             svr_A_il, svr_alpha_il, svr_beta_i)

  # B. Aggregate utility given Alternative Allocation
  fl_util_alter_alloc <- ffi_disc_v_alt(fl_rho, df_input_ib, svr_A_i_l0, svr_alpha_o_i, svr_beta_i)

  # C. Generate rho specific REV
  it_w_exp_min <- min(df_rev_Ail_onerho %>%
                        filter(!!sym(svr_V_star_Q_il) >= fl_util_alter_alloc) %>%
                        pull(!!sym(svr_inpalc)))
  fl_REV <- 1 - (it_w_exp_min/fl_teacher_increase_number)


  # Return
  return(fl_REV)
}

Test loop vs sapply results.

# Loop Results
start_time_loop <- Sys.time()
ar_util_rev_loop <- rep(NA, length(ar_rho))
for (it_rho_ctr in seq(1:length(ar_rho))) {
  fl_rho <- ar_rho[it_rho_ctr]
  df_queue_il_long_onerho <- df_queue_il_long %>% filter(!!sym(svr_rho) == it_rho_ctr)
  ar_util_rev_loop[it_rho_ctr] <-
    ffi_disc_rev_onerho_test(fl_rho=fl_rho,
                             fl_teacher_increase_number=fl_teacher_increase_number,
                             df_input_ib=df_input_ib,
                             df_queue_il=df_queue_il_long_onerho)
}
end_time_loop <- Sys.time()
print(paste0('LOOP loop time:', end_time_loop - start_time_loop))
## [1] "LOOP loop time:4.96390700340271"
# Sapply Results
df_queue_il_long_onerho <- df_queue_il_long %>% filter(!!sym(svr_rho) == 4)
ar_util_rev_sapply <- sapply(ar_rho, ffi_disc_rev_onerho_test,
                               fl_teacher_increase_number=fl_teacher_increase_number,
                               df_input_ib=df_input_ib,
                               df_queue_il=df_queue_il_long_onerho)

# Compare and Print, only the 4th result should match up because sapply is not changing input data matrix
print('ar_util_rev_sapply')
## [1] "ar_util_rev_sapply"
print(ar_util_rev_sapply)
## [1] 0.1748155 0.1825646 0.3130074 0.9492620
print('ar_util_rev_loop')
## [1] "ar_util_rev_loop"
print(ar_util_rev_loop)
## [1] 0.8358856 0.8356089 0.8306273 0.9492620

DPLYR Functionalize Optimal Allocation Multiple Rhos

Call the ffi_disc_rev_onerho function, whose parameters include two dataframes df_input_ib and df_queue_il. df_queue_ib is invariant to \(\rho\), and df_queue_il differs depending on \(\rho\).

Group df_queue_il_long by \(\rho\) subgroups, and use do anything to call the ffi_disc_rev_onerho function.

Generate value mt_rev

# ffi_disc_Diall_onerho: function, discrete, allocation D_i = 1 to D_max, one rho (rho)
# This function invokes two functions, project function ffi_disc_Di0_onerho, and REconTools Function ff_panel_cumsum_grouplast.
ffi_disc_rev_onerho <- function(fl_rho,
                                fl_teacher_increase_number,
                                df_input_ib, df_queue_il_with_V,
                                svr_A_i_l0 = 'A_i_l0', svr_alpha_o_i = 'alpha_o_i',
                                svr_inpalc = 'Q_il',
                                svr_beta_i = 'beta_i',
                                svr_V_star_Q_il = 'V_star_Q_il'){
  if(length(fl_rho)>1){
    # rho could be fed in an an array, with all identical values
    fl_rho <- fl_rho[1]
  }

  # B. Aggregate utility given Alternative Allocation
  fl_util_alter_alloc <- df_input_ib %>%
      mutate(v_altern_i = !!sym(svr_beta_i)*((!!sym(svr_A_i_l0) + !!sym(svr_alpha_o_i))^fl_rho)) %>%
      summarize(v_altern_unif_i = sum(v_altern_i)^(1/fl_rho)) %>%
      pull()

  # C. Generate rho specific REV
  it_w_exp_min <- min(df_queue_il_with_V %>%
                        filter(!!sym(svr_V_star_Q_il) >= fl_util_alter_alloc) %>%
                        pull(!!sym(svr_inpalc)))
  fl_REV <- 1 - (it_w_exp_min/fl_teacher_increase_number)

  # Return
  return(list(it_w_exp_min=it_w_exp_min,
              fl_REV=fl_REV))
}

REV Function

ffi_disc_rev <- function(ar_rho,
                         fl_teacher_increase_number,
                         df_input_ib, df_queue_il_long_with_V,
                         svr_rho = 'rho', svr_rho_val = 'rho_val',
                         svr_A_i_l0 = 'A_i_l0', svr_alpha_o_i = 'alpha_o_i',
                         svr_inpalc = 'Q_il',
                         svr_beta_i = 'beta_i',
                         svr_V_star_Q_il = 'V_star_Q_il'){

    # Evaluate REV
    ar_util_rev_loop <- df_queue_il_long_with_V %>%
      group_by(!!sym(svr_rho)) %>%
      do(rev = ffi_disc_rev_onerho(fl_rho = .[[svr_rho_val]],
                                   fl_teacher_increase_number = fl_teacher_increase_number,
                                   df_input_ib = df_input_ib, df_queue_il_with_V = .,
                                   svr_A_i_l0 = svr_A_i_l0, svr_alpha_o_i = svr_alpha_o_i,
                                   svr_inpalc = svr_inpalc,
                                   svr_beta_i = svr_beta_i,
                                   svr_V_star_Q_il = svr_V_star_Q_il)$fl_REV) %>%
      unnest() %>% pull()

    # Return Matrix
    mt_rho_rev <- cbind(ar_rho, ar_util_rev_loop)
    colnames(mt_rho_rev) <- c(svr_rho_val,'REV')
    tb_rho_rev <- as_tibble(mt_rho_rev) %>% rowid_to_column(var = svr_rho)

# Retrun
return(tb_rho_rev)
}

Call Function.

# the func version supercede the earlier versions, because they have some more outputs
# but the nonfunction version have additional variables inside needed for line by line code
df_queue_il_long <- df_queue_il_long_func
df_alloc_i_long <- df_alloc_i_long_func

# Solve for REV
start_time_nest <- Sys.time()
tb_rho_rev <- ffi_disc_rev(ar_rho, fl_teacher_increase_number, df_input_ib, df_queue_il_long)
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(rev)`
ar_util_rev_loop_func <- tb_rho_rev %>% pull(REV)
end_time_nest <- Sys.time()
print(paste0('DPLYR nested loop time:', end_time_nest - start_time_nest))
## [1] "DPLYR nested loop time:0.0836429595947266"
print('ar_util_rev_loop_func')
## [1] "ar_util_rev_loop_func"
print(ar_util_rev_loop_func)
## [1] 0.8358856 0.8356089 0.8306273 0.9492620
# Compare Results, if 0 match
sum(ar_util_rev_loop - ar_util_rev_loop_func)
## [1] 0