@@ -74,6 +74,8 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
74
74
75
75
adj_no_qnaires = no_qnaires / (st_resprate * permission_rate * sch_resprate )
76
76
adj_no_schools = ifelse(all_schools == ' No' ,ceiling(no_schools / sch_resprate ),nrow(datum )) %> % round()
77
+ # ##
78
+ if (adj_no_schools > no_schools ){stop(paste0(' Adjust the number of schools to a maximum of: ' ,floor(sch_resprate * nrow(datum ))))}
77
79
# Calculate the overall sampling fraction
78
80
total_enrolment = sum(datum $ enrolment , na.rm = T )
79
81
overall_sampling_fraction = (adj_no_qnaires ) / sum(datum $ enrolment , na.rm = T )
@@ -85,7 +87,7 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
85
87
# #Selection of certainty schools
86
88
initial_SI = round(sum(datum $ enrolment , na.rm = T )/ adj_no_schools )
87
89
revised_SI = initial_SI
88
- mod_datum = datum
90
+ mod_datum = datum
89
91
# Initialize certainty_schools
90
92
certainty_schools = data.frame (mod_datum [0 , ])
91
93
@@ -132,14 +134,18 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
132
134
round(StudentWeight ),numberOfclasses = selectClasses ),
133
135
collapse = ' ,' ),NA ),School_Selected = ' Yes' )
134
136
137
+ # ##
138
+ common_variables = c(' school_ID' , ' school' ,' enrolment' ,' RevisedMOS' , ' category' , ' SchoolWeight' , ' StudentWeight' , ' classes' , ' School_Selected' )
139
+
135
140
# ###Updated frame only containing non-certainty schools
136
141
if (nrow(certainty_schools )> 0 )
137
142
{
138
143
non_certainty_schools = mod_datum %> %
139
144
dplyr :: filter(eval(parse(text = paste0(' !(' ,paste0(' school_ID' ,' ==' ,certainty_schools $ school_ID , collapse = ' |' ),' )' ))))
140
145
} else {non_certainty_schools = mod_datum }
141
146
# ####
142
- maximum_enrolment <<- max(non_certainty_schools $ enrolment , na.rm = T )
147
+ # maximum_enrolment <<- max(non_certainty_schools$enrolment, na.rm = T)
148
+ maximum_enrolment <<- max(datum $ enrolment , na.rm = T )
143
149
144
150
# ####
145
151
@@ -169,7 +175,7 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
169
175
#
170
176
min_measure_of_size <<- non_certainty_schools $ sampling_factor [non_certainty_schools $ enrolment < non_certainty_schools $ sampling_factor ][1 ]
171
177
# Total number of schools to be systematically selected
172
- total_schools_to_select <<- adj_no_schools - nrow(certainty_schools )
178
+ total_schools_to_select <<- adj_no_schools - nrow(certainty_schools )
173
179
# ## Adjust measures of size for noncertainty schools
174
180
if (! is.na(min_measure_of_size ))
175
181
{
@@ -244,16 +250,36 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
244
250
} else {}
245
251
246
252
# Select the schools using the computed indices
247
- common_variables = c(' school_ID' , ' school' ,' enrolment' ,' RevisedMOS' , ' category' , ' SchoolWeight' , ' StudentWeight' , ' classes' , ' School_Selected' )
253
+ if (nrow(mod_datum )!= 0 )
254
+ {
248
255
non_certainty_schools = non_certainty_schools %> % dplyr :: select(all_of(common_variables )) %> % mutate_all(as.character )
256
+ }
257
+
249
258
certainty_schools = certainty_schools %> % dplyr :: select(all_of(common_variables ))%> % mutate_all(as.character )
250
259
#
251
260
no_schools_MOS_adj <<- sum(non_certainty_schools $ RevisedMOS == min_measure_of_size , na.rm = T )
252
261
schools_MOS_adjusted <<- global_sf * no_schools_MOS_adj
253
- #
254
- selected_schools = bind_rows(non_certainty_schools ,certainty_schools )
262
+ # Conversion to common type
263
+
264
+ # selected_schools = bind_rows(non_certainty_schools ,certainty_schools)
265
+
266
+ if (nrow(non_certainty_schools )== 0 & nrow(certainty_schools )> 0 ){
267
+ selected_schools = certainty_schools
268
+ } else if (nrow(non_certainty_schools )> 0 & nrow(certainty_schools )== 1 ){
269
+ selected_schools = non_certainty_schools
270
+ }else if (nrow(non_certainty_schools )> 0 & nrow(certainty_schools )== 1 ){
271
+ selected_schools = bind_rows(non_certainty_schools ,certainty_schools )
272
+ }else {}
273
+
274
+
275
+
255
276
256
277
} else {
278
+ total_schools_to_select <<- nrow(datum )
279
+ schools_MOS_adjusted = 0
280
+ min_measure_of_size = min(datum $ enrolment , na.rm = T )
281
+ maximum_enrolment = max(datum $ enrolment , na.rm = T )
282
+
257
283
common_variables = c(' school_ID' , ' school' ,' enrolment' ,' RevisedMOS' , ' category' , ' SchoolWeight' , ' StudentWeight' , ' classes' , ' School_Selected' )
258
284
259
285
selected_schools = datum %> %
@@ -271,7 +297,7 @@ sampling_function = function(datum = frame_schools,no_qnaires = 2906, no_schools
271
297
# {
272
298
# stop(paste0('Consider increasing either the number of ',unique(datum$category),' schools to be selected or adjust the school or student response rate'))
273
299
# } else{}
274
- if (any(total_schools_to_select < = schools_MOS_adjusted | (! is.na(min_measure_of_size ) & (min_measure_of_size < 0 | min_measure_of_size > maximum_enrolment ))))
300
+ if (any(input $ census == ' No ' & ( total_schools_to_select < = schools_MOS_adjusted | (! is.na(min_measure_of_size ) & (min_measure_of_size < 0 | min_measure_of_size > maximum_enrolment ) ))))
275
301
{
276
302
output $ warningUI = renderUI( {
277
303
fluidRow(tags $ div(tags $ span(style = " color: red;" ,paste0(' Consider increasing either the number of ' ,unique(global_datum $ category ),' schools to ' ,floor(schools_MOS_adjusted ),' or adjust the school or student response rate.' ))))
0 commit comments