Title: | Handy Plots |
---|---|
Description: | Several handy plots for quickly looking at the relationship between two numeric vectors of equal length. Quickly visualize scatter plots, residual plots, qq-plots, box plots, confidence intervals, and prediction intervals. |
Authors: | Jonathan Schwartz |
Maintainer: | Jonathan Schwartz <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1.3 |
Built: | 2024-11-15 03:35:01 UTC |
Source: | https://github.com/cran/handyplots |
given two numeric vectors of equal length, plot a scatter plot of the data, the regression line, and a confidence interval for the mean of a new observation or the prediction interval for a single new observation.
ciplot(x, y, x0 = NULL, int = c("p","c"), level = 0.95, relationship = c("linear","quadratic","cubic","sqrt","exponential","reciprocal","log"), show.range = TRUE, user.xlim = NULL, user.ylim = NULL)
ciplot(x, y, x0 = NULL, int = c("p","c"), level = 0.95, relationship = c("linear","quadratic","cubic","sqrt","exponential","reciprocal","log"), show.range = TRUE, user.xlim = NULL, user.ylim = NULL)
x |
a numeric vector of length > 3 |
y |
a numeric vector of length > 3 (equal in length to |
x0 |
the x value at which you wish to make a prediction ( |
int |
interval type. |
level |
the confidence level at which you wish to predict. |
relationship |
the type of relationship that the two vectors share. |
show.range |
logical. If |
user.xlim |
the interval of x values the user wishes to display in the plot. If left unspecified, it will be |
user.ylim |
the interval of y values the user wishes to display in the plot. If left unspecified, it will be |
If x0
is outside the domain of x
, ciplot will extrapolate the data and predict a value of yhat
for the given x0
. This may be dangerous, depending on how your data behaves outside the existing domain.
Jonathan Schwartz
Montgomery, D. C., Peck, E. A., Vining, G. G. (2013), Introduction to Linear Regression Analysis, Hoboken, NJ: John Wiley & Sons, Inc.
##predicting the mean petal width of an iris whose petal length is 2.5 ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="conf") ##predicting a single new observation of the petal width of an iris whose petal length is 2.5 ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="pred") ##extrapolating the data to predict the mean of the width of an iris's petal whose petal length is 8 ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf") ##zooming in to the previous graph and removing the dotted red lines ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf",show.range=FALSE, user.xlim=c(7.5,8.5),user.ylim=c(2.6,3.2))
##predicting the mean petal width of an iris whose petal length is 2.5 ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="conf") ##predicting a single new observation of the petal width of an iris whose petal length is 2.5 ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="pred") ##extrapolating the data to predict the mean of the width of an iris's petal whose petal length is 8 ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf") ##zooming in to the previous graph and removing the dotted red lines ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf",show.range=FALSE, user.xlim=c(7.5,8.5),user.ylim=c(2.6,3.2))
A quick way to see the name and class of every colum of a data frame
colID(df)
colID(df)
df |
A data frame you wish to look at |
Returns a data frame where column 1 is the names of the columns of the original data frame, and column 2 is the class of the column of the original data frame.
Jonathan Schwartz
colID(iris)
colID(iris)
A quick way to cook up some fake data.
fakedata(formula, s = 0.25)
fakedata(formula, s = 0.25)
formula |
A formula which describes the relationship you wish your fake data to have to an existing numeric vector. For example, if you have a numeric vector |
s |
A numeric value which describes the amount of variablity you want your fake data to have. If |
Quickly cooking up fake data may be useful for experimenting with differnt plotting functions in R with data that you can control. You can control the relationship between your data and an existing vector, and you can control the variablity of the data, i.e. how closely correlated the fake data is to the existing vector. You also know that the residuals are normally distributed with mean 0, which satisfies a major assumption of linear regression.
The function returns a numeric vector.
Jonathan Schwartz
x=sample(0:1000,100) y=fakedata(3*x+10) #y is a vector of fake data which will have a linear relationship with x plot(x,y) cor(x,y) #x and y are very highly correlated y2=fakedata(3*x+10,1) #increasing the value of s decreases the correlation plot(x,y2) cor(x,y2) #x and y2 are not as highly correlated ##you can also, of course do non-linear relationships y3=fakedata(sqrt(1/x)) plot(x,y3)
x=sample(0:1000,100) y=fakedata(3*x+10) #y is a vector of fake data which will have a linear relationship with x plot(x,y) cor(x,y) #x and y are very highly correlated y2=fakedata(3*x+10,1) #increasing the value of s decreases the correlation plot(x,y2) cor(x,y2) #x and y2 are not as highly correlated ##you can also, of course do non-linear relationships y3=fakedata(sqrt(1/x)) plot(x,y3)
If you have two numeric vectors of equal length you can use quickplot to quickly look at the potential relationship between them in four graphs at once.
Quickplot will show you a scatter plot with a regression line, a qq-plot to check the normality of the residuals, a residual plot to check the constancy and correlation of the residuals, and a boxplot for a quick overview of the spread of the two vectors, and two historgrams to see the distributions of the two vectors.
quickplot(x, y)
quickplot(x, y)
x |
A numeric vector of length > 3 |
y |
A numeric vector of length > 3 (equal in length to |
Jonathan Schwartz
Montgomery, D. C., Peck, E. A., Vining, G. G. (2013), Introduction to Linear Regression Analysis, Hoboken, NJ: John Wiley & Sons, Inc.
plot
,
abline
,
lm
,
qqnorm
,
qqline
,
resplot
,
boxplot
##quickly looking at the relationship between iris petal length and iris petal width quickplot(iris$Petal.Length,iris$Petal.Width)
##quickly looking at the relationship between iris petal length and iris petal width quickplot(iris$Petal.Length,iris$Petal.Width)
Plot the fitted values vs the studentized or standardized residuals for a glm
or lm
object.
resplot(model, zoom = NULL, highlight.outliers = FALSE, residuals = c("student","standard"))
resplot(model, zoom = NULL, highlight.outliers = FALSE, residuals = c("student","standard"))
model |
a regression model with any number of predictors. Must be a |
zoom |
what range of residuals you wish to show in your plot. By default, zoom is |
highlight.outliers |
logical. If |
residuals |
which type of residuals to use. Studentized residuals are used by default, but can be specified with |
A residual plot shows the fitted values of the response variable on the x-axis and the studentized or standardized residuals on the y-axis. It can be used to check for correlated residuals or non-constant variance of the residuals, both of which would violate the residual assumptions of a linear model. It can also be used to check for outliers, as a value below -3 or above 3 would indicate a residual which is more than 3 standard deviations from the mean of 0.
Jonathan Schwartz
Montgomery, D. C., Peck, E. A., Vining, G. G. (2013), Introduction to Linear Regression Analysis, Hoboken, NJ: John Wiley & Sons, Inc.
plot
,
abline
,
lm
,
glm
,
predict
,
rstudent
,
rstandard
##plot a residual plot to check the model assumptions for a linear ##model of iris petal length as a predicted by iris petal width model<-lm(iris$Petal.Length~iris$Petal.Width) resplot(model) ##highlight the one outlier resplot(model,highlight.outliers=TRUE) ##zoom in to only show the residuals between -1 and 1 resplot(model,zoom=1)
##plot a residual plot to check the model assumptions for a linear ##model of iris petal length as a predicted by iris petal width model<-lm(iris$Petal.Length~iris$Petal.Width) resplot(model) ##highlight the one outlier resplot(model,highlight.outliers=TRUE) ##zoom in to only show the residuals between -1 and 1 resplot(model,zoom=1)
The function takes a text file or text string and outputs a barplot
of the most frequently occuring words.
wordcount(file = "", n, decreasing = TRUE, text)
wordcount(file = "", n, decreasing = TRUE, text)
file |
A text file whose location is interpreted relative to the current working directory (given by |
n |
The number of words to show in the |
decreasing |
If |
text |
If you wish to enter text as an inline argument rather than as a file on your computer, you can enter your text as this argument and leave |
Jonathan Schwartz
myfile <- file.path(tempdir(), "wordcounttest.txt") write("Four four four four. Three three three. Two two. One.",file=myfile ) wordcount(myfile ,4) ##or text can be entered inline wordcount(text="Four four four four. Three three three. Two two. One.",n=4)
myfile <- file.path(tempdir(), "wordcounttest.txt") write("Four four four four. Three three three. Two two. One.",file=myfile ) wordcount(myfile ,4) ##or text can be entered inline wordcount(text="Four four four four. Three three three. Two two. One.",n=4)