-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpinch.R
63 lines (42 loc) · 1.76 KB
/
pinch.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -----------------------------------------------------------------------
# Pinch force data
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
#
# Overview of the analyses
#
# These data are subjected to a principal components analysis.
# -----------------------------------------------------------------------
# Last modified 21 March 2006
# ------------------ input the data --------------------
pinchmat <- pinch
pinchtime <- seq(0,150,len=151)/600
pinchrange <- c(0,0.25)
# ----------- create fd object --------------------
# use 31 bsplines of order 6
nbasis <- 153
norder <- 4
pinchbasis <- create.bspline.basis(pinchrange, nbasis, norder)
lambda <- 1e-6
pinchfdPar <- fdPar(pinchbasis, 2, lambda)
pinchfd <- smooth.basis(pinchtime, pinchmat, pinchfdPar)$fd
names(pinchfd$fdnames) <- c("Arg. No.", "Replicates", "Force (N)")
# plot all the curves
par(mfrow=c(1,1),pty="m")
plot(pinchfd)
title("Pinch Force Curves")
# plot each curve along with the data
plotfit.fd(pinchmat, pinchtime, pinchfd)
# plot the residuals, with cases sorted by size of mean squared residuals
plotfit.fd(pinchmat, pinchtime, pinchfd, residual=TRUE, sort=TRUE)
# --------------- do a PCA (light smoothing, varimax rotation) --------
lambda <- 1e-4
pcafdPar <- fdPar(pinchbasis, 2, lambda)
pinchpca.fd <- pca.fd(pinchfd, nharm=3, pcafdPar)
pinchpca.fd <- varmx.pca.fd(pinchpca.fd)
plot.pca.fd(pinchpca.fd)
pincheigvals <- pinchpca.fd[[2]]
par(mfrow=c(1,1),pty="s")
plot(1:19,log10(pincheigvals[1:19]),type="b",
xlab="Eigenvalue Number", ylab="Log 10 Eigenvalue")
abline(lsfit(4:19, log10(pincheigvals[4:19])), lty=2)