R/si_linear.R

Defines functions si_linear

Documented in si_linear

#' Calculate Si using linear method
#'
#' @name si_linear
#'
#' @description Calculate Si using linear method
#'
#' @param x A Dataframe
#' @param avg_type Choosing average type. So far "simple", "geometric" and "harmonic" average are availableƧ
#'
#' @return A data frame
#'
#' @examples
#' x <- data.frame(rnorm(20),rnorm(20),rnorm(20),rnorm(20))
#' si_linear(x,avg_type = "simple")


si_linear <- function(x,avg_type = "simple")
{

# calculating composite index (ci)
y<- calc_average(x,avg_type)

# tidying up
row.names(y) <- NULL
colnames(y) <- c("ci")

d <- dim(x)[2]
s_i <- NULL

for (i in 1:d)
{
  m <- lm(y$ci~as.matrix(x[,i]))
  m_s <- summary(m)
  r_2 <- m_s$r.squared
  s_i <- rbind(s_i,r_2)
}

row.names(s_i) <- NULL
si_normalized <-s_i/sum(s_i)
colnames(s_i) <- "si"

return(list(s_i,si_normalized))
}

Try the compindexR package in your browser

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

compindexR documentation built on Nov. 26, 2023, 1:06 a.m.