File: eof.R

package info (click to toggle)
r-cran-spacetime 1.2-8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,300 kB
  • sloc: sh: 13; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,201 bytes parent folder | download | duplicates (4)
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
EOF = function(x, how = c("spatial", "temporal"), returnPredictions = TRUE, 
		...) { 
	.Deprecated("eof")
	stopifnot(is(x, "STFDF"))
	sp = x@sp
	index = index(x@time)
	x = as(x, "xts") # matrix
	if (how[1] == "spatial") {
		pr = prcomp(~., data.frame(t(x)), ...)
		if (! returnPredictions)
			return(pr)
		x = addAttrToGeom(sp, data.frame(predict(pr)), TRUE)
	} else if (how[1] == "temporal") {
		pr = prcomp(~., data.frame(x), ...)
		if (! returnPredictions)
			return(pr)
		x = xts(data.frame(predict(pr)), index)
	} else
		stop("unknown mode: use spatial or temporal")
	names(x) = paste("EOF", 1:ncol(x), sep="")
	x
}

eof = function(x, how = c("spatial", "temporal"), returnEOFs = TRUE, ...) { 
	stopifnot(is(x, "STFDF"))
	sp = x@sp
	index = index(x@time)
	x = as(x, "xts") # matrix
	switch(how[1], 
		"spatial" = {
			pr = prcomp(~., data.frame(x), ...)
			if (! returnEOFs)
				return(pr)
			x = addAttrToGeom(sp, data.frame(pr$rotation), FALSE)
		},
		"temporal" = {
			pr = prcomp(~., data.frame(t(x)), ...)
			if (! returnEOFs)
				return(pr)
			x = xts(data.frame(pr$rotation), index)
		},
		stop("unknown mode: use spatial or temporal")
	)
	names(x) = paste("EOF", 1:ncol(x), sep="")
	x
}