qqplot()
options distribution
and probs
c("car", "hexbin")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
set.seed(123)
rnorm(200, 175, 10)
x <-hist(x, xlab="x", ylab="N", breaks="FD")
hist(x, freq=FALSE, xlab="x", ylab="relative frequency",
breaks="FD", main="Histogram und normal PDF")
rug(jitter(x))
curve(dnorm(x, mean(x), sd(x)), lwd=2, col="blue", add=TRUE)
hist(x, freq=FALSE, xlab="x", breaks="FD",
main="Histogram and density estimate")
lines(density(x), lwd=2, col="blue")
rug(jitter(x))
To compare the histograms from two groups, see histbackback()
from package Hmisc
.
rnorm(100, mean=175, sd=7)
y <-stem(y)
The decimal point is 1 digit(s) to the right of the |
15 | 669
16 | 134
16 | 5566777789
17 | 0011112222233333334444444
17 | 5555566666677777788888888999
18 | 0000000001111233334444
18 | 55667779
19 | 2
40
Nj <- 3
P <- rnorm(P*Nj, mean=100, sd=15)
DV <- gl(P, Nj, labels=c("Control", "Group A", "Group B")) IV <-
boxplot(DV ~ IV, ylab="Score", col=c("red", "blue", "green"),
main="Boxplot of scores in 3 groups")
stripchart(DV ~ IV, pch=16, col="darkgray", vert=TRUE, add=TRUE)
DV[IV == "Control"]
xC <- DV[IV == "Group A"]
xA <-boxplot(xC, xA)
5
Nj <- rnorm(Nj, 20, 2)
DV1 <- rnorm(Nj, 25, 2)
DV2 <- c(DV1, DV2)
DV <- gl(2, Nj)
IV <- tapply(DV, IV, FUN=mean) Mj <-
dotchart(DV, gdata=Mj, pch=16, color=rep(c("red", "blue"), each=Nj),
gcolor="black", labels=rep(LETTERS[1:Nj], 2), groups=IV,
xlab="AV", ylab="group",
main="individual results and means from 2 groups")
25
Nj <- 4
P <- sample(1:6, P*Nj, replace=TRUE)
dice <- gl(P, Nj) IV <-
stripchart(dice ~ IV, xlab="Result", ylab="group", pch=1, col="blue",
main="Dice results: 4 groups", sub="jitter-method", method="jitter")
stripchart(dice ~ IV, xlab="Result", ylab="group", pch=16, col="red",
main="Dice results: 4 groups", sub="stack-method", method="stack")
rnorm(200)
DV1 <- rf(200, df1=3, df2=15)
DV2 <-qqplot(DV1, DV2, xlab="quantile N(0, 1)", ylab="quantile F(3, 15)",
main="Comparison of quantiles from N(0, 1) and F(3, 15)")
rnorm(100, mean=175, sd=7)
height <-qqnorm(height)
qqline(height, col="red", lwd=2)
round(rnorm(10), 1)
vec <- ecdf(vec)
Fn <-plot(Fn, main="Empirical cumulative distribution function")
curve(pnorm, add=TRUE, col="gray", lwd=2)
200
N <- 2
P <- rnorm(N, 100, 15)
x <- 0.5*x + rnorm(N, 0, 10)
y <- gl(P, N/P, labels=LETTERS[1:P]) IV <-
plot(x, y, pch=c(4, 16)[unclass(IV)], lwd=2,
col=c("black", "blue")[unclass(IV)],
main="Joint distribution per group")
legend(x="topleft", legend=c("group A", "group B"),
pch=c(4, 16), col=c("black", "blue"))
Pooled groups
library(car)
dataEllipse(x, y, xlab="x", ylab="y", asp=1, levels=0.5, lwd=2, center.pch=16,
col="blue", main="Joint distribution of two variables")
legend(x="bottomright", legend=c("Data", "centroid", "distribution ellipse"),
pch=c(1, 16, NA), lty=c(NA, NA, 1), col=c("black", "blue", "blue"))
5000
N <- rnorm(N, 100, 15)
xx <- 0.4*xx + rnorm(N, 0, 10)
yy <-plot(xx, yy, pch=16, col=rgb(0, 0, 1, 0.3))
Based on a 2-D kernel density estimate
smoothScatter(xx, yy, bandwidth=4)
library(hexbin)
hexbin(xx, yy, xbins=20)
res <-plot(res)
summary(res)
'hexbin' object from call: hexbin(x = xx, y = yy, xbins = 20)
n = 5000 points in nc = 214 hexagon cells in grid dimensions 26 by 21
cell count xcm ycm
Min. : 9.0 Min. : 1.00 Min. : 44.83 Min. :-5.868
1st Qu.:156.2 1st Qu.: 2.00 1st Qu.: 81.19 1st Qu.:23.484
Median :240.5 Median : 8.00 Median :101.46 Median :40.020
Mean :241.7 Mean : 23.36 Mean :101.18 Mean :40.089
3rd Qu.:324.8 3rd Qu.: 31.00 3rd Qu.:120.83 3rd Qu.:56.395
Max. :499.0 Max. :133.00 Max. :157.78 Max. :90.498
try(detach(package:car))
try(detach(package:hexbin))
R markdown - markdown - R code - all posts