# calcWeights: Calculates the relative weight of each observation In ACCLMA: ACC & LMA Graph Plotting

## Description

This function receives a matrix after the averageSameXs function has been used on it and calculates the relative weight of each observation by dividing its weight by the total weights. If at least one observation doesn't have a weight specified the function assumes all the observations are of equal weight

## Usage

 `1` ```calcWeights(mat) ```

## Arguments

 `mat` a matrix after the averageSameXs function has been used on it

## Value

A matrix with the updated weights column

## Author(s)

Tal Carmi, Liat Gaziel

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30``` ```d <- c(1,1,3,4) e <- c(5,6,7,8) f <- c(1,1,1,1) mydata <- data.frame(d,e,f) names(mydata) <- c("X","Y","Weight") mydata<-averageSameXs(mydata) calcWeights(mydata) ## The function is currently defined as function (mat) { n <- size(mat) zeroWeight <- 0 sumWeight <- 0 for (i in 1:n) { if (is.null(mat[i, 3]) || is.na(mat[i, 3]) || mat[i, 3] == 0) { zeroWeight <- 1 } sumWeight <- sumWeight + mat[i, 3] } if (zeroWeight == 1) { mat = 1/n return(mat) } for (i in 1:n) { mat[i, 3] <- mat[i, 3]/sumWeight } return(mat) } ```

ACCLMA documentation built on May 2, 2019, 8:49 a.m.