I have generated the following:
x=
E1 E2 E3
D1 0 0 1
D2 1 0 3
D3 0 2 0
y=
E1 E2 E3
D1 0 0 1.75
D2 1.75 0 1.3125
D3 0 3.5 0
Where x and y are linked by:
y =sum(x) * x / (rowSums(x)%o%colSums(x))
N=x[x[1:3,]>0]
R=y[y[1:3,]>0]
Now suppose I ONLY have N and R linked in this way below where each N
corresponds to an R
N R
1 1.7500
2 3.5000
1 1.7500
3 1.3125
Is there a way to generate matrix "x" and matrix "y" having
only the N
and the R as above?
--
View this message in context:
http://www.nabble.com/Generating-these-matrices-going-backwards-tf4807447.html#a13754521
Sent from the R help mailing list archive at Nabble.com.
Maybe something like this?
N<-c(1,2,1,3)
## create empty matrix
x<-diag(0,3)
## fill off diagonal
x[row(x)==col(x)+1]<-N[1:2]
# fill 3rd column
x[1:2,3]<-N[3:4]
Or create a function and return both x and y
mat3<-function(N)
{
x<-diag(0,3)
# fill each element separately
x[2,1]<-N[1]
x[3,2]<-N[2]
x[1,3]<-N[3]
x[2,3]<-N[4]
dimnames(x)<-list(c("D1", "D2", "D3"),
c("E1", "E2", "E3"))
y =sum(x) * x / (rowSums(x)%o%colSums(x))
list(x=x,y=y)
}
mat3(N)
$x
E1 E2 E3
D1 0 0 1
D2 1 0 3
D3 0 2 0
$y
E1 E2 E3
D1 0.00 0.0 1.7500
D2 1.75 0.0 1.3125
D3 0.00 3.5 0.0000
francogrex wrote:>
> I have generated the following:
>
> x=
> E1 E2 E3
> D1 0 0 1
> D2 1 0 3
> D3 0 2 0
>
> y=
> E1 E2 E3
> D1 0 0 1.75
> D2 1.75 0 1.3125
> D3 0 3.5 0
>
> Where x and y are linked by:
> y =sum(x) * x / (rowSums(x)%o%colSums(x))
>
> N=x[x[1:3,]>0]
> R=y[y[1:3,]>0]
>
> Now suppose I ONLY have N and R linked in this way below where each N
> corresponds to an R
>
> N R
> 1 1.7500
> 2 3.5000
> 1 1.7500
> 3 1.3125
>
> Is there a way to generate matrix "x" and matrix "y"
having only the N
> and the R as above?
>
>
>
--
View this message in context:
http://www.nabble.com/Generating-these-matrices-going-backwards-tf4807447.html#a13756103
Sent from the R help mailing list archive at Nabble.com.
Hi, thanks but the way you are doing it is to assign the values of N in the x matrix, knowing from the example I have given where they are supposed to be. While the assumption is, you ONLY have values of N and R and do NOT know where they would be placed in the x and y matrix a-priori, but their position has to be derived from only the (N and R) dataframe you have. Chris Stubben wrote:> > Maybe something like this? > > N<-c(1,2,1,3) > ## create empty matrix > x<-diag(0,3) > ## fill off diagonal > x[row(x)==col(x)+1]<-N[1:2] > # fill 3rd column > x[1:2,3]<-N[3:4] > > Or create a function and return both x and y > > mat3<-function(N) > { > x<-diag(0,3) > # fill each element separately > x[2,1]<-N[1] > x[3,2]<-N[2] > x[1,3]<-N[3] > x[2,3]<-N[4] > dimnames(x)<-list(c("D1", "D2", "D3"), c("E1", "E2", "E3")) > y =sum(x) * x / (rowSums(x)%o%colSums(x)) > list(x=x,y=y) > } > mat3(N) >-- View this message in context: http://www.nabble.com/Generating-these-matrices-going-backwards-tf4807447.html#a13763015 Sent from the R help mailing list archive at Nabble.com.