Skip to content

Commit afb01c1

Browse files
committed
update of Nov 3rd, error in Spencers code
1 parent 0a34d84 commit afb01c1

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

R/fRegress.R

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,8 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
7373

7474
if (is.fdPar(y)) y <- y$fd
7575

76-
print(class(y))
77-
print("inside fRegress.fd")
78-
79-
print("calling fRegressArgCheck")
80-
8176
arglist <- fRegressArgCheck(y, xfdlist, betalist, wt)
8277

83-
print("fRegressArgCheck called")
84-
8578
yfdobj <- arglist$yfd
8679
xfdlist <- arglist$xfdlist
8780
betalist <- arglist$betalist
@@ -100,7 +93,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
10093
# ----------------------------------------------------------------
10194

10295
# extract dependent variable information
103-
print("extract dependent variable information")
10496
ycoef <- yfdobj$coefs
10597
ycoefdim <- dim(ycoef)
10698
N <- ycoefdim[2]
@@ -218,8 +210,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
218210

219211
eigchk(Cmat)
220212

221-
print("Cmat, Dmat computed")
222-
223213
# solve for coefficients defining BETA
224214

225215
Lmat <- chol(Cmat)
@@ -228,7 +218,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
228218

229219
betacoef <- Cmatinv %*% Dmat
230220

231-
print("betacoef computed")
232221
# set up fdPar objects for reg. fns. in BETAESTLIST
233222

234223
betaestlist <- betalist
@@ -248,8 +237,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
248237
betaestlist[[j]] <- betafdParj
249238
}
250239

251-
print("betalist set up")
252-
253240
# set up fd objects for predicted values in YHATFDOBJ
254241

255242
nfine <- max(501,10*ynbasis+1)
@@ -267,8 +254,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
267254

268255
df <- NA
269256

270-
print("yhatfdobj set up")
271-
272257
# -----------------------------------------------------------------------
273258
# Compute pointwise standard errors of regression coefficients
274259
# if both y2cMap and SigmaE are supplied.
@@ -351,8 +336,6 @@ fRegress.fd <- function(y, xfdlist, betalist, wt=NULL,
351336
# Set up output list object
352337
# -------------------------------------------------------------------
353338

354-
print("Set up output list object")
355-
356339
fRegressList <-
357340
list(yfdobj = yfdobj,
358341
xfdlist = xfdlist,

R/fRegress.double.R

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
5151
# as predict(List). In this call List can be any object of the
5252
# "".
5353

54-
# Last modified 25 August 2020 by Jim Ramsay
54+
# Last modified 3 November 2020 by Jim Ramsay
5555

5656
# check Y and compute sample size N
5757

58-
print("inside fRegress.numeric")
58+
print("inside fRegress.double")
5959

6060
if (!inherits(y, "numeric")) stop("Y is not a numeric vector.")
6161

@@ -74,14 +74,13 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
7474
N <- dim(ymat)[1]
7575
p <- length(xfdlist)
7676

77-
print("preliminaries")
77+
print("computing Rmat")
7878

7979
Zmat <- NULL
8080
Rmat <- NULL
8181
pjvec <- rep(0,p)
8282
ncoef <- 0
8383
for (j in 1:p) {
84-
print(j)
8584
xfdj <- xfdlist[[j]]
8685
print(class(xfdj))
8786
xcoef <- xfdj$coefs
@@ -92,7 +91,6 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
9291
pjvec[j] <- bnbasis
9392
Jpsithetaj <- inprod(xbasis,bbasis)
9493
Zmat <- cbind(Zmat,crossprod(xcoef,Jpsithetaj))
95-
print("betafdParj$estimate")
9694
if (betafdParj$estimate) {
9795
lambdaj <- betafdParj$lambda
9896
if (lambdaj > 0) {
@@ -116,10 +114,11 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
116114
# set up the linear equations for the solution
117115
# -----------------------------------------------------------
118116

119-
print("Cmat and Dmat")
120-
121117
# solve for coefficients defining BETA
122118

119+
print("assembling Cmat and Dmat")
120+
121+
123122
if (any(wt != 1)) {
124123
rtwt <- sqrt(wt)
125124
Zmatwt <- Zmat*rtwt
@@ -131,23 +130,22 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
131130
Dmat <- t(Zmat) %*% ymat
132131
}
133132

134-
# print("solving")
135-
136133
eigchk(Cmat)
137134

135+
print("solving equation")
136+
138137
Cmatinv <- solve(Cmat)
139138

140139
betacoef <- Cmatinv %*% Dmat
141140

142-
143141
# compute and print degrees of freedom measure
144142

145143
df <- sum(diag(Zmat %*% Cmatinv %*% t(Zmat)))
146144

147-
print("betaestlist")
148-
149145
# set up fdPar object for BETAESTFDPAR
150146

147+
print("setting up beetaestlist")
148+
151149
betaestlist <- betalist
152150
mj2 <- 0
153151
for (j in 1:p) {
@@ -167,7 +165,7 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
167165

168166
# set up fd object for predicted values
169167

170-
print("yhatmat")
168+
print("computing yhatmat")
171169

172170
yhatmat <- matrix(0,N,1)
173171
for (j in 1:p) {
@@ -200,12 +198,13 @@ fRegress.double <- function(y, xfdlist, betalist, wt=NULL,
200198
# if both y2cMap and SigmaE are supplied.
201199
# -----------------------------------------------------------------------
202200

203-
print("standard errors")
204201

205202
if (!(is.null(y2cMap) || is.null(SigmaE))) {
206203

207204
# check dimensions of y2cMap and SigmaE
208205

206+
print("computing bvar, betastderrlist, and c2bMap")
207+
209208
y2cdim <- dim(y2cMap)
210209
if (y2cdim[2] != dim(SigmaE)[1]) stop(
211210
"Dimensions of Y2CMAP not correct.")

man/fRegress.Rd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,14 @@ dimnames(rgnContr3) <- list('', CanadianWeather$place, c('const',
527527

528528
const365 <- create.constant.basis(c(0, 365))
529529
region.fd.Atlantic <- fd(matrix(rgnContr3[,,2], 1), const365)
530-
str(region.fd.Atlantic)
530+
# str(region.fd.Atlantic)
531531
region.fd.Continental <- fd(matrix(rgnContr3[,,3], 1), const365)
532532
region.fd.Pacific <- fd(matrix(rgnContr3[,,4], 1), const365)
533533
region.fdlist <- list(const=rep(1, 35),
534534
region.Atlantic=region.fd.Atlantic,
535535
region.Continental=region.fd.Continental,
536536
region.Pacific=region.fd.Pacific)
537-
str(TempRgn.mdl$betalist)
537+
# str(TempRgn.mdl$betalist)
538538

539539
beta1 <- with(Temp.fd, fd(basisobj=basis, fdnames=fdnames))
540540
beta0 <- fdPar(beta1)
@@ -589,6 +589,13 @@ fRegressout <- fRegress(kneefd, xfdlist, betalist)
589589
all.equal(fRegressout, knee.hip.f)
590590
\dontshow{)}
591591

592+
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
593+
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
594+
group <- gl(2,10,20, labels=c("Ctl","Trt"))
595+
weight <- c(ctl, trt)
596+
597+
fRegress.D9 <- fRegress(weight ~ group)
598+
592599
#See also the following demos:
593600

594601
#demo('canadian-weather', package='fda')

0 commit comments

Comments
 (0)