idx_invcov: Create Inverse Covariance-Weighted Index from Several...

View source: R/idx_invcov.R

idx_invcovR Documentation

Create Inverse Covariance-Weighted Index from Several Variables

Description

With code by Cyrus Samii, see https://github.com/cdsamii/make_index/blob/master/r/index_comparison.R

Usage

idx_invcov(..., wt, fill_na = TRUE, na.rm = TRUE)

Arguments

...

One or more unquoted variables

fill_na

Option to fill missing values from any variable with linear predictions from all of the other variables. TRUE by default.

na.rm

Option to remove NA's when calculating mean index. TRUE by default.

Value

A vector with the mean index

Examples


var1 <- rnorm(100, mean = 0.5, sd = 0.25)
var2 <- rnorm(100, mean = -1, sd = 0.5)
var3 <- rnorm(100, mean = 1, sd = 1)

idx_invcov(var1, var2, var3)

library(dplyr)

df <- tibble(var1, var2, var3)

mutate(df, idx_var = idx_invcov(var1, var2, var3))


graemeblair/stdidx documentation built on April 19, 2023, 6:48 a.m.