Recipe: How to find correlations among feature variables in R?

How to find correlations among feature variables in R?

This recipe helps you correlate the fields in a dataset to determine the relationship between them and pick the right features for modelling.

This recipe uses the cor (), cov (), rcorr() packages in R to establish relationships between the features. It then outputs a correlation matrix.

What is a Feature variable ?
A feature variable refers to the fields in a dataset used for analytics or machine learning. Feature selection, also known as variable selection is the process of selecting a subset of relevant features (variables) from the dataset for in model construction.

What is R ?
R is a programming language used for statistics and data science computing. R has very powerful libraries (almost 12,000) for performing data analytics including regression, classification, visualisation etc.

In [ ]:
# -------------------------------------------------
# How to find correlations among feature variables in R
# -------------------------------------------------
# load library and data



# Correlations/covariances among numeric variables 
# Use listwise deletion of missing data. 
cor(mtcars, use="complete.obs", method="kendall") 
cov(mtcars, use="complete.obs")

# Correlations with significance levels
rcorr(as.matrix(mtcars), type="pearson")

# Correlation matrix from mtcars
# with mpg, cyl, and disp as rows 
# and hp, drat, and wt as columns 
x <- mtcars[1:3]
y <- mtcars[4:6]
cor(x, y)

Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from eClerx
1 developer from Peritus
1 developer from Altimetrik
1 developer from KPMG
1 developer from Vodafone
1 developer from ANAC
1 developer from LTI
1 developer from YASH Technologies
1 developer from Cognizant
1 developer from New Delhi DataPoint