# nrsq: Calculate a coefficient of determination (R-squared) In dnegrey/miscTools: R package with miscellaneous tools

## Description

`nrsq()` calculates the coefficient of determination, or R-squared value, between an independent variable `x` and a dependent variable `y`. Note that when `na.rm = FALSE` (default), missing values of `x` will be replaced with `1` and a flag identifying the missings will be included as an additive term in the model. Otherwise, only non-missing records are fit.

## Usage

 `1` ```nrsq(x, y, na.rm = FALSE) ```

## Arguments

 `x` numeric vector (independent variable) `y` numeric vector (dependent variable) `na.rm` logical value indicating whether missing values of `x` (and their corresponding `y` values) should be removed

## Value

A numeric value with class "`mt_nrsq`" that indicates the proportion of the variance in the dependent variable that is predictable from the independent variable.

`lm`, `summary.lm`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```# basic example without missing values nrsq(mtcars\$hp, mtcars\$mpg) # add some missing values x <- ifelse(runif(length(mtcars\$hp)) < 0.30, NA, mtcars\$hp) # include missings with adjustment nrsq(x, mtcars\$mpg, na.rm = FALSE) # exclude missings entirely nrsq(x, mtcars\$mpg, na.rm = TRUE) # evaluate a whole data frame of predictors temp <- lapply(mtcars[c("disp", "hp", "wt", "qsec")], nrsq, y = mtcars\$mpg) data.frame( VarName = names(temp), RSquared = as.numeric(unlist(temp)), stringsAsFactors = FALSE ) ```