R/comire.internal.R

Defines functions .psdp_multi .pssq_multi .mixdensity_multi .labelling_c_multi .labelling_b_multi .psdp_uni .pssq_uni .mixdensity_uni .labelling_c_uni .labelling_b_uni .pssq_gaussian

Documented in .labelling_b_multi .labelling_b_uni .labelling_c_multi .labelling_c_uni .mixdensity_multi .mixdensity_uni .psdp_multi .psdp_uni .pssq_gaussian .pssq_multi .pssq_uni

#-----------------
#Internal functions comire.continuous

#' @name comire.internal
#' @title Internal Functions of CoMiRe package
#' @keywords internal
#' 
.pssq_gaussian <- function(index, data, cluster, locations) sum((data[cluster==index] - locations[index])^2)

#-----------------
#Internal functions comire continuous with confounders

#' @name comire.internal
#' @keywords internal
#' 
.labelling_b_uni <- function(i, w, phi, f0i, f1i)
{
  probs <- w*((1-phi[i,])*f0i[i] + phi[i,]*f1i[i])
  if(any(probs<0)) probs[probs<0]=0
  sample(1:ncol(phi), 1, prob=probs)
}

#

#' @name comire.internal
#' @keywords internal
#' 
.labelling_c_uni <- function(i, y, z, nu, theta, tau, ga)
{
  probs <- nu*stats::dnorm(y[i], theta+z[i]*ga , sqrt(1/tau))
  if(any(probs<0)) probs[probs<0]=0
  sample(1:length(nu), 1, prob=probs)
}

#

#' @name comire.internal
#' @keywords internal
#' 
.mixdensity_uni <- function(i, y, z, nu, theta, tau, ga)
{
  kernels <- stats::dnorm(y[i], (theta+z[i]*ga) , sqrt(1/tau))
  fji <- sum(nu * kernels)
  fji
}

#

#' @name comire.internal
#' @keywords internal
#' 
.pssq_uni <- function(index, y, z, cluster, theta, gamma) {
  sum((y[cluster==index] - 
         (theta[index]+z[cluster==index]*gamma))^2)}

#

#' @name comire.internal
#' @keywords internal
#' 
.psdp_uni <- function(index, y, z, cluster){
  sum(y[cluster==index]*z[cluster==index])
}

#

#' @name comire.internal
#' @keywords internal
#' 
.labelling_b_multi <- function(i, w, phi, f0i, f1i)
{
  probs <- w*((1-phi[i,])*f0i[i] + phi[i,]*f1i[i])
  if(any(probs<0)) probs[probs<0]=0
  sample(1:ncol(phi), 1, prob=probs)
}

#

#' @name comire.internal
#' @keywords internal
#' 
.labelling_c_multi <- function(i, y, z, nu, theta, tau, ga)
{
  probs <- nu*stats::dnorm(y[i], theta+as.vector(crossprod(z[i,],ga)) , sqrt(1/tau))
  if(any(probs<0)) probs[probs<0]=0
  sample(1:length(nu), 1, prob=probs)
}

#

#' @name comire.internal
#' @keywords internal
#' 
.mixdensity_multi <- function(i, y, z, nu, theta, tau, ga) 
{
  kernels <- stats::dnorm(y[i], theta+as.vector(crossprod(z[i,],ga)) , sqrt(1/tau))
  fji <- sum(nu * kernels)
  fji
}

#

#' @name comire.internal
#' @keywords internal
#' 
.pssq_multi <- function(y,times,z,gamma,theta){
  H <- length(theta)
  sapply(1:H, function(x) 
    crossprod( y-(theta[x]*rep(1,times)+crossprod(t(z),gamma)) ))
}

#

#' @name comire.internal
#' @keywords internal
#' 
.psdp_multi <- function(index, y, z, cluster){
  sum(y[cluster==index]*z[cluster==index])
}

Try the CoMiRe package in your browser

Any scripts or data that you put into this service are public.

CoMiRe documentation built on Aug. 23, 2023, 5:09 p.m.