Skip to content

Commit

Permalink
loops_additional_origin created
Browse files Browse the repository at this point in the history
  • Loading branch information
perblock committed Jan 4, 2024
1 parent da45e9f commit 608f841
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion R/2b_effectFunctions_loops.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,54 @@ loops_resource_covar <-
return(update * state[[resource.attribute.index]]$data[edge])
}


#' loops_additional_origin
#'
#' This effect models loops for cases in which individuals have more than one
#' origin. The additional origin not specified in the mobility data is included
#' as a resource.attribute.index.
#' The question modelled is: Do individuals stay in the additional location of
#' origin, compared to going to a different location?
#'
#' @param dep.var
#' @param resource.attribute.index
#' @param state
#' @param cache
#' @param i
#' @param j
#' @param edge
#' @param update
#' @param getTargetContribution
#'
#' @return Returns the change statistic or target statistic of the effect for
#' internal use by the estimation algorithm.
#' @keywords internal
loops_additional_origin <-
function(dep.var = 1,
resource.attribute.index,
state,
cache,
i,
j,
edge,
update,
getTargetContribution = FALSE) {

if (getTargetContribution) {
res_index <- (state[[dep.var]]$data[,1] == i) * (state[[dep.var]]$data[,2] == j)
cont <- sum(res_index * (state[[resource.attribute.index]]$data == j))
return(cont)
}

dest.of.res <- state[[dep.var]]$data[edge,2]
second.orig.of.res <- state[[resource.attribute.index]]$data[edge]

if(dest.of.res == second.orig.of.res){
return(update)
}

return(0)

}



Expand Down

0 comments on commit 608f841

Please sign in to comment.