-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFstat.fd.R
37 lines (25 loc) · 890 Bytes
/
Fstat.fd.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
Fstat.fd <- function(y,yhat,argvals=NULL) {
# observed, predicted and where to evaluate
if( is.numeric(yhat) ) yhat <- as.vector(yhat)
if( (is.vector(y) & !is.vector(yhat)) | (is.fd(y) &!is.fd(yhat)) ) {
stop("y and yhat must both be either scalars or functional data objects.")
}
if( is.fd(y) ) {
rangeobs <- y$basis$range
rangehat <- yhat$basis$range
if( !prod(rangeobs == rangehat) ){
stop("y and yhat do not have the same range")
}
if(is.null(argvals)){
argvals <- seq(rangeobs[1],rangeobs[2],length.out=101)
}
yvec <- eval.fd(argvals,y)
yhatvec <- eval.fd(argvals,yhat)
F <- apply(yhatvec,1,var)/apply( (yvec-yhatvec)^2,1,mean)
} else {
yvec <- y
yhatvec <- yhat
F <- var(yhatvec)/mean( (yvec-yhatvec)^2 )
}
return( list(F=F,argvals=argvals) )
}