View source: R/Equitable_Transform.R
| AI_Bmult_NA | R Documentation |
It is based on equitable slope (A) and shift (B) matrices and data set I Both A and B can be tored efficiently by only retaining 1 column from each matrix NA values are allowed If a transform exists, this function can construct a complete data set from either: 1. a complete data set 2. A data set of only an average profile in variable t or a profile for some individual or location 3. profile at one rbitrary location is available 4. scattered observations across the different "individuals" or locations x for different values of t Examples of each are given. Only 2*length of x dimension + length of t dimension are needed to reconstruct system If the data is not precisely equitable then more data provides a better estimate. # Errors are also given to show how closely the system matches the equitbale one that is assumed.
AI_Bmult_NA(A, I, B = NULL, zero = 0, maxA = NULL)
A |
equitable slope matrix NxN |
I |
two dimensional data set MxN that can contain many NA values |
B |
equitable shift matrix MxM |
zero |
Value to be subtracted from I to generate B default NULL (0) |
maxA |
Values in the slope matrix larger than this threshold are not used in the transform Default NULL |
Equitable transform of data that fills in many of the NA values based on the tranformed values
#case 1 not shown. It is less interesting unless it is a noisy or corrupted system
#case 2: Use an average profile with 2 vectors from the matrices to construct
# transformed data. (2N+M data points)
# To illustrate the idea first use an an equitable data set to construct
# equitable matrix A and shift matrix B
#from which vectors f an u are extracted. These are used to reconstruct the matrices when desired.
d<-eg4(2,2); Td<-transformE(d) # make a data set and find the transform and associated matrices
f<-Td$E.s[,1] # form
u<-Td$E.b[,1]
I<-Td$smat;I[]<-NA; I[,"Row_Ave"]<-Td$smat[,"Row_Ave"]
# the 3 necessary components are made so show what they look like and then construct system
plot(f,type="b",main="f(x) profile used for Equitable matrix A")
plot(u,type="b",main="u(x) profile used with matrix A\nto make for shift matrix B")
plot(I[, "Row_Ave"],type="b",,main="Average profile used for reconstruction")
imagenan(I,main="Only the average profile is defined")
A<-make_A(f=f)
B<-make_B(xref=1,orig=u,A=A,uflag=TRUE)
TI<-AI_Bmult_NA(A=A,I=I,B=B)
attributes(TI)
imagenan(TI$xme,main="Reconstructed data set from Average profile")
#data successfully reconstructed
# case 3 profile at x=10 available but it is somewhat noisy
xref<-10; I<-Td$smat;I[]<-NA;
I[,xref]<-Td$smat[,xref]
plot(I[, xref],type="b",main="Profile (no Noise)")
I[,xref]<-I[,xref]+rnorm(nrow(I),mean=0,sd=(1/10*sd(I[,xref],na.rm=TRUE)))
plot(I[, xref],type="b",main="Profile used for reconstruction (with noise)")
imagenan(I,main=paste("data only from profile at location x=",xref))
TI<-AI_Bmult_NA(A=A,I=I,B=B)
attributes(TI)
imagenan(TI$xme,main=paste("Reconstructed data set from noisy profile at location x=",xref))
# case 3 profile at x=10 available but is completely different from original
xref<-10; I<-Td$smat;I[]<-NA;
I[,xref]<-eg5(2,2)[,xref]
plot(I[, xref],type="b",main="Average profile used for reconstruction")
imagenan(I,main=paste("data only from profile at location x=",xref))
TI<-AI_Bmult_NA(A=A,I=I,B=B)
attributes(TI)
imagenan(TI$xme,main=paste("Reconstructed data set from profile at location x=",xref))
#case 5 scattered information around the data set
#using random points over the data set only works
#if the system has the same equitable sense as the matrices
I<-Td$smat
numspaces<-nrow(I)
column_location<-sample(1:ncol(I), numspaces, replace=TRUE)
I_NA<-I; I_NA[]<-NA;g<-rep(NA,nrow(I))
for(t in 1:nrow(I_NA)){I_NA[t,column_location[t]]<-I[t,column_location[t]];
g[t]<-I[t,column_location[t]]}
plot(g,type="b",main=paste("Data set from random points on x as function of t" ))
imagenan(I_NA,main=paste("Data set from random points on x" ))
A<-make_A(f=f)
B<-make_B(xref=1,orig=u,A=A,uflag=TRUE)
TI<-AI_Bmult_NA(A=A,I=I_NA,B=B)
attributes(TI)
imagenan(TI$xme,
main=paste("Data set reconstructed from random points on x as function of t" ))
#case 5 scattered information around the data set that is noisy
#using random points over the data set assumes the system has
# the same equitable sense as the matrices
I<-Td$smat ;g<-rep(NA,nrow(I))
numspaces<-10*nrow(I) ;g<-rep(NA,numspaces)
column_location<-sample(1:(ncol(I)-1), numspaces, replace=TRUE)
I_NA<-I; I_NA[]<-NA;g<-rep(NA,nrow(I))
Ieg4<-eg4(2,2)
Ieg4<-Ieg4+ rnorm(prod(dim(Ieg4)),mean=0,sd=(1/10*sd(Ieg4,na.rm=TRUE)))
imagenan(Ieg4,main="Noise added")
for(t in 1:numspaces){
I_NA[t%%nrow(I)+1,column_location[t]]<-Ieg4[t%%nrow(I)+1,column_location[t]]
g[t]<-Ieg4[t%%nrow(I)+1,column_location[t]]
}
imagenan(I_NA,main=paste("Data set from random points on x" ))
A<-make_A(f=f)
B<-make_B(xref=1,orig=u,A=A,uflag=TRUE)
TI<-AI_Bmult_NA(A=A,I=I_NA,B=B)
attributes(TI)
imagenan(TI$xme,
main=paste("Data set reconstructed from random points",
"(from eg4 with noise) on x as function of t" ))
imagenan(TI$xsd,
main=paste("Std Dev in reconstruction from random points\n",
" (from eg4 with noise) on x as function of t" ))
#error values show where the system was not equitable
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.