-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ Collate: | |
'get_bioreg.R' | ||
'evaluate_range.R' | ||
'make_blocks.R' | ||
'optme.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
### ========================================================================= | ||
### optimization function for cluster distribution (meta) | ||
### ========================================================================= | ||
#' Optimization function to create equal-sized strata in the 'make_blocks' function | ||
#' | ||
#' Not to be called directly by the user. | ||
#' @author Philipp Brun | ||
#' @export | ||
optme=function(x,nms,grps,tot){ | ||
|
||
# determine number of bservations in each groups from initial step | ||
grp=sapply(grps,"sum") | ||
|
||
# aggregate remaining observations by suggested cluster grouping | ||
x=as.numeric(as.character(x)) | ||
agg.vals=aggregate(nms,by=list(x),FUN="sum") | ||
|
||
for(i in 1:length(grp)){ | ||
|
||
if(i%in%agg.vals$Group.1){ | ||
grp[i]=agg.vals$x[which(agg.vals$Group.1==i)]+grp[i] | ||
} | ||
|
||
} | ||
|
||
# Calculate difference from equal distribution | ||
pen=(grp-tot/length(grp))^2 | ||
|
||
return(sum(pen)) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.