When I began to study R software, I was really impressed with the function
cor. As you knows, the 'cor' function returns all
r values of every possible pairs of matrix or data.frame provided that it consists of numeric data only. For example,
cor(mtcars[1:5]) acts just as expected.
cor(iris) returns error because the data.frame consist of both numeric and factor variable.
If you wanted to get
p values as well as
r values, you should use
cor.test instead of
cor.test can deal with only one pair of numeric vectors of the same length, neither a matrix nor a data.frame. Furthermore, if you wanted to get the
intercept of simple linear regression line of xyplot, you had to perform
lm test for every pairs of numeric variables of the data.frame.
My idea is that a single function deals with data.frame of mixed numeric, logical and factor variables, select numeric variables, perform
lm to get
intercept of every pairs of the variables for exploratory analysis. It can save my time and effort.
Use of mycor function is simple. Just call mycor with a data.frame. For example, just call
cor, it does not result in an error.
require(lattice) require(mycor) mycor(iris)
The mycor function reurns an object of class "mycor". This can be saved for print, summarize and plot. A S3 method for class
formula can be used to function
print.mycor shows the r values and th p values similar to the function
mycor class object can be summarized with summary function, summary().
out=mycor(iris,alternative="greater", method="kendall",digits=2) out1=mycor(~mpg+disp+hp+wt,data=mtcars) summary(out1)
mycor function uses cor.test internally, so you can use all options of
cor.test - namely
Probably most valuable function is plot. It is not a new function. It uses internally one of two popular function : graphics::pairs() and lattice::parallelplot(). In fact, plot.mycor function have four types of plot : Three variants of pairs and parallelplot. Call function
plot with no option makes pairs().
But if you specify the groups, you can get more pretty plot. You can use extra arguments which can used in pairs() or parallelplot().
plot(out,groups=species,main="Test of mycor::plot")
type=2 option, you can get histogram at diagonal panel.
type=3 option, you can get correlation plot at upper panels.
type=4 option, you can get parallelplot.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.