Skip to content

Commit c7e1b30

Browse files
committed
re-committing files
1 parent 0a62500 commit c7e1b30

28 files changed

+833
-757
lines changed

.github/workflows/R-CMD-check.yaml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
1+
# fda
2+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
23
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
34
on:
45
push:
@@ -18,7 +19,7 @@ jobs:
1819
fail-fast: false
1920
matrix:
2021
config:
21-
- {os: macOS-latest, r: 'release'}
22+
- {os: macos-latest, r: 'release'}
2223
- {os: windows-latest, r: 'release'}
2324
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2425
- {os: ubuntu-latest, r: 'release'}
@@ -29,18 +30,21 @@ jobs:
2930
R_KEEP_PKG_SOURCE: yes
3031

3132
steps:
32-
- uses: actions/checkout@v2
33-
- uses: r-lib/actions/setup-tinytex@v2
34-
- uses: r-lib/actions/setup-pandoc@v1
33+
- uses: actions/checkout@v3
3534

36-
- uses: r-lib/actions/setup-r@v1
35+
- uses: r-lib/actions/setup-pandoc@v2
36+
37+
- uses: r-lib/actions/setup-r@v2
3738
with:
3839
r-version: ${{ matrix.config.r }}
3940
http-user-agent: ${{ matrix.config.http-user-agent }}
4041
use-public-rspm: true
4142

42-
- uses: r-lib/actions/setup-r-dependencies@v1
43+
- uses: r-lib/actions/setup-r-dependencies@v2
4344
with:
44-
extra-packages: rcmdcheck
45+
extra-packages: any::rcmdcheck
46+
needs: check
4547

46-
- uses: r-lib/actions/check-r-package@v1
48+
- uses: r-lib/actions/check-r-package@v2
49+
with:
50+
upload-snapshots: true

R/.DS_Store

0 Bytes
Binary file not shown.

R/eval.surp.R

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ eval.surp <- function(evalarg, Wfdobj, nderiv=0) {
9292
return(Smat)
9393
}
9494

95+
# Note: derivative values computed using Pmat rather than Bmat
96+
# This needs correcting
97+
9598
# First derivative:
9699

97100
if (nderiv == 1) {

R/smooth.pos.R

+19-15
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ smooth.pos <- function(argvals, y, WfdParobj, wtvec=rep(1,n), conv=1e-4,
2525
# an N by NCURVE matrix, where N is the number of observed
2626
# curve values for each curve and NCURVE is the number of
2727
# curves observed.
28-
# If the functional data are muliivariate, this array will be
28+
# If the functional data are multivariate, this array will be
2929
# an N by NCURVE by NVAR matrix, where NVAR the number of
3030
# functions observed per case. For example, for the gait
3131
# data, NVAR = 2, since we observe knee and hip angles.
32-
# WFDPAROBJ... A functional parameter or fdPar object. This object
32+
# WFDPAROBJ... An fd or an fdPar object. This object
3333
# contains the specifications for the functional data
3434
# object to be estimated by smoothing the data. See
3535
# comment lines in function fdPar for details.
3636
# The functional data object WFD in WFDPAROBJ is used
3737
# to initialize the optimization process.
3838
# Its coefficient array contains the starting values for
39-
# the iterative minimization of mean squared error.
39+
# the iterative minimization of mean squared error, and
40+
# this coefficient array must be either a K by NCURVE
41+
# matrix or a K by NUCRVE by NVAR array, where K
42+
# is the number of basis functions.
43+
# If WFDPAROBJ is NULL, it will be initialized to
44+
# a matrix or array of zeros.
4045
# WTVEC ... a vector of weights, a vector of N one's by default.
4146
# CONV ... convergence criterion, 0.0001 by default
4247
# ITERLIM ... maximum number of iterations, 50 by default.
@@ -60,7 +65,7 @@ smooth.pos <- function(argvals, y, WfdParobj, wtvec=rep(1,n), conv=1e-4,
6065
# FLIST objects are indexed linear with curves varying inside
6166
# variables.
6267

63-
# Last modified 16 November 2021 by Jim Ramsay
68+
# Last modified 17 January 2023 by Jim Ramsay
6469

6570
# check ARGVALS
6671

@@ -76,7 +81,7 @@ smooth.pos <- function(argvals, y, WfdParobj, wtvec=rep(1,n), conv=1e-4,
7681

7782
# check Y
7883

79-
y = as.matrix(y)
84+
y <- as.matrix(y)
8085
ychk <- ycheck(y, n)
8186
y <- ychk$y
8287
ncurve <- ychk$ncurve
@@ -85,19 +90,18 @@ smooth.pos <- function(argvals, y, WfdParobj, wtvec=rep(1,n), conv=1e-4,
8590

8691
# check WfdParobj and get LAMBDA
8792

88-
WfdParobj <- fdParcheck(WfdParobj,curve)
89-
lambda <- WfdParobj$lambda
90-
91-
# the starting values for the coefficients are in FD object WFDOBJ
92-
93+
if (inherits(WfdParobj, "fdPar") || inherits(WfdParobj, "fd")) {
94+
if (inherits(WfdParobj, "fd")) WfdParobj <- fdPar(WfdParobj)
95+
} else {
96+
stop(paste("Argument WFDPAROBJ is neither an fdPar object",
97+
"or an fd object."))
98+
}
9399
Wfdobj <- WfdParobj$fd
94100
Lfdobj <- WfdParobj$Lfd
95-
basisobj <- Wfdobj$basis # basis for W(argvals)
96-
nbasis <- basisobj$nbasis # number of basis functions
97-
98-
# set up initial coefficient array
99-
101+
basisobj <- Wfdobj$basis
102+
nbasis <- basisobj$nbasis
100103
coef0 <- Wfdobj$coefs
104+
lambda <- WfdParobj$lambda
101105

102106
# check WTVEC
103107

R/smooth.surp.R

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
smooth.surp <- function(argvals, Wbin, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
1+
smooth.surp <- function(argvals, y, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
22
iterlim=50, dbglev=0) {
3-
# Smooths the relationship of Y to ARGVALS using weights in WTVEC by fitting
3+
# Smooths the relationship of Y to ARGVALS using weights in WTVEC by fitting
44
# surprisal functions to a set of surprisal transforms of choice
55
# probabilities, where the surprisal transformation of each probability is
66
# W(p_m) = -log_M (p_m), m=1, ..., M,
@@ -20,7 +20,7 @@ smooth.surp <- function(argvals, Wbin, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
2020
# surprisal values for each curve. It is assumed that
2121
# that these argument values are common to all observed
2222
# curves.
23-
# WBIN ... A matrix containingg the values to be fit.
23+
# Y ... A matrix containing the values to be fit.
2424
# This will be an NBIN by M matrix, where NBIN is the
2525
# number of bins containing choice probabilities and M is
2626
# the number of options in a specific question or rating
@@ -70,15 +70,14 @@ smooth.surp <- function(argvals, Wbin, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
7070
n <- length(argvals)
7171
onesobs <- matrix(1,n,1)
7272

73-
# Check Wbin, an n by M-1 matrix of surprisal values.
73+
# Check y, an n by M-1 matrix of surprisal values.
7474
# It may not contain negative values.
7575

76-
Wbin <- as.matrix(Wbin)
77-
Wbindim <- dim(Wbin)
78-
M <- Wbindim[2]
79-
if (Wbindim[1] != n)
80-
stop("The length of ARGVALS and the number of rows of WBIN differ.")
81-
# if (min(Wbin) < 0) stop("WBIN contains negative values.")
76+
y <- as.matrix(y)
77+
ydim <- dim(y)
78+
M <- ydim[2]
79+
if (ydim[1] != n)
80+
stop("The length of ARGVALS and the number of rows of Y differ.")
8281

8382
# Check WfdPar and extract WBASIS, WNBASIS, Wlambda and WPENALTY.
8483
# Note that the coefficient matrix is not used.
@@ -134,7 +133,7 @@ smooth.surp <- function(argvals, Wbin, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
134133

135134
# Set up list object for data required by PENSSEfun
136135

137-
surpList <- list(argvals=argvals, Wbin=Wbin, wtvec=wtvec, Kmat=Kmat,
136+
surpList <- list(argvals=argvals, y=y, wtvec=wtvec, Kmat=Kmat,
138137
Zmat=Zmat, Phimat=Phimat, M=M)
139138
# --------------------------------------------------------------------
140139
# loop through variables and curves
@@ -248,12 +247,13 @@ smooth.surp <- function(argvals, Wbin, Bmat0, WfdPar, wtvec=NULL, conv=1e-4,
248247
D2SSE <- surpResult$D2SSE
249248
DvecSmatDvecB <- surpResult$DvecSmatDvecB
250249

251-
result <- list(Wfd=Wfd, Bmat=Bmat, f=f, gvec=gvec, hmat=hmat,
250+
surpFd <- list(Wfd=Wfd, Bmat=Bmat, f=f, gvec=gvec, hmat=hmat,
252251
PENSSE=PENSSE, DPENSSE=DPENSSE, D2PENSSE=D2PENSSE,
253252
SSE=SSE, DSSE=DSSE, D2SSE=D2SSE,
254253
DvecSmatDvecB=DvecSmatDvecB)
254+
class(surpFd) <- 'surpfd'
255255

256-
return(result)
256+
return(surpFd)
257257
}
258258

259259
# ------------------------------------------------------------------
@@ -266,7 +266,7 @@ surp.fit <- function(x, surpList) {
266266
# extract objects from surpList
267267

268268
argvals <- surpList$argvals
269-
Wbin <- surpList$Wbin
269+
y <- surpList$y
270270
wtvec <- surpList$wtvec
271271
Kmat <- surpList$Kmat
272272
Zmat <- surpList$Zmat
@@ -288,7 +288,7 @@ surp.fit <- function(x, surpList) {
288288
sumexpXmat <- as.matrix(apply(expXmat,1,sum))
289289
Pmat <- expXmat/(sumexpXmat %*% matrix(1,1,M))
290290
Smat <- -Xmat + (log(sumexpXmat) %*% matrix(1,1,M))/logM
291-
Rmat <- Wbin - Smat
291+
Rmat <- y - Smat
292292
vecBmat <- matrix(Bmat,K*(M-1),1,byrow=TRUE)
293293
vecRmat <- matrix(Rmat,n*M, 1,byrow=TRUE)
294294
vecKmat <- kronecker(diag(rep(1,M-1)),Kmat)

data/refinery.rda

3.1 KB
Binary file not shown.

inst/.DS_Store

100755100644
2 KB
Binary file not shown.

0 commit comments

Comments
 (0)