R For Beginners: Basic R Code for Common Statistical Procedures Part I
This article is originally published at https://dmwiig.net
An R tutorial by D. M. Wiig
This section gives examples of code to perform some of the most common elementary statistical procedures. All code segments assume that the package ‘car’ has been loaded and the file ‘Freedman’ has been loaded as the active dataset. Use the menu from the R console to load the ’car’ dataset or use the following command line to access the CRAN site list and packages:
install.packages()
Once the ’car’ package has been downloaded and installed use the following command to make it the active library.
require(car)
Load the ‘Freedman’ data file from the dataset ‘car’
data(Freedman, package="car")
List basic descriptives of the variables:
summary(Freedman)
Perform a correlation between two variables using Pearson, Kendall or Spearman’s correlation:
cor(filename[,c("var1","var2")], use="complete.obs", method="pearson")
cor(filename[,c("var1","var2")], use="complete.obs", method="spearman")
cor(filename[,c("var1","var2")], use="complete.obs", method="kendall")
Example:
cor(Freedman[,c("crime","density")], use="complete.obs", method="pearson")
cor(Freedman[,c("crime","density")], use="complete.obs", method="kendall")
cor(Freedman[,c("crime","density")], use="complete.obs", method="spearman")
In the next post I will discuss basic code to produce multiple correlations and linear regression analysis. See other tutorials on this blog for more R code examples for basic statistical analysis.
Thanks for visiting r-craft.org
This article is originally published at https://dmwiig.net
Please visit source website for post related comments.