Displaying 20 results from an estimated 10000 matches similar to: "Compute correlation matrix for panel data with, specific ordering"
2009 Jun 26
3
Compute correlation matrix for panel data with specific ordering
Hello All,
I have a panel date - here a small-scale example:
df <-
data.frame(cbind(rep(c("AUT","BEL","DEN","GER"),4),cbind(rep(c(1999,2000,2001,2002),4)),sample(10,16,replace=T)))
names(df) <- c("country","year","x")
SORT <- c("GER","BEL","DEN","AUT")
I need to compute the
2007 Nov 28
4
Replacing values job
Hallo,
I have two vectors of different lengths which contain the same set of
values:
X < -c(2,6,1,7,4,3,5)
Y <- c(1,1,6,4,6,1,4,1,2,3,6,6,1,2,4,4,5,4,1,7,6,6,4,4,7,1,2)
How can I replace the values in Y with the index (!) of the corresponding
values in X. So 2 appears in X in the first coordinate, so all 2’s in Y
should be replaced by 1, etc.
Thank you for your help,
Serguei
2007 Nov 28
1
Order observations in a dataframe
Dear All,
Suppose I have the following dataframe:
country;weight;group
bul;10;1
cze;12;1
grc;12;1
hun;12;1
prt;12;1
rom14;1
fra;29;2
ita;29;2
gbr;29;2
aut;10;3
bel;12;3
The "group" variable denotes the id-number of a group of countries. How can
I re-label the groups in the descending order of their cumulative "weight",
which wound be:
country;weight;group
fra;29;1
ita;29;1
2006 Dec 14
3
Delete all dimnames
Hello, how can I get rid of all dimnames so that:
$amat
Var3 Var2 Var1
8 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
7 1 1 1 0 1 0 0 0 1 0 0 0 0 0 0
6 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0
5 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0
4 1 0 1 1 0 0 1 0 0 0 0 1 0 0 0
3 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0
2 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0
2005 Nov 23
2
vector of permutated products
Given an x-vector with, say, 3 elements, I would like to compute the
following vector of permutated products
(1-x1)*(1-x2)*(1-x3)
(1-x1)*(1-x2)*x3
(1-x1)*x2*(1-x3)
x1*(1-x2)*(1-x3)
(1-x1)*x2*x3
x1*(1-x2)*x3
x1*x2*(1-x3)
x1*x2*x3
Now, I already have the correctly sorted matrix of permutations! So, the
input looks something like:
#input
x<-c(0.3,0.1,0.2)
Nx<-length(x)
Ncomb<-2^Nx
2007 Nov 20
1
How to map clusters to a correlation matrix
Dear All,
I have several socio-economic and geographic variables for the 27 EU
countries. I would to use these data to derive a correlation matrix between
groups of countries (for a different application).
I thought of using kmeans to cluster the groups, and then calibrate between
group correlations using distances between the centroids, and within group
correlations using distances in a cluster
2007 Feb 06
1
Questions on counts by case
Hi all,
for the data below I would like to
1. generate a dummy variable for each group "gr" of the same composition by
people, then save each portion in a separate file,
2. compute the frequency of "1"'s in "x" for each person by group
"gr". So, "mike" will have freq=2/3, as he has two "1" and one "0" in 3
groups.
2006 Sep 22
3
Compiling a contingency table of counts by case
I have asked a similar question before but this time
the problem is somewhat more involved. I have the
following data:
case;name;x
1;Joe;1
1;Mike;1
1;Zoe;1
2;Joe;1
2;Mike;0
2;Zoe;1
2;John;1
3;Mike;1
3;Zoe;0
3;Karl;0
I would like to count the number of "case"
in which any two "name"
a. both have "x=1",
b. the first has "x=0" - the second has
2007 Feb 26
1
Adding duplicates by rows
Hi,
I am trying to add duplicates of matrix "mat" by row. Commands
subset(mat,duplicated(rownames(mat)))
or
mat[which(duplicated(rownames(mat))),]
return only half of the required indices. How can I find the remaining
ones, ie the matches, so that I can add them up?
Thanks,
Serguei
___________________________________________________________________
Austrian Institute of Economic
2005 Dec 04
4
Construct a data.frame in a FOR-loop
Say I have a FOR-loop for computing powers (just a trivial example)
for(i in 1:5)
{
x<-i^2
y<-i^3
}
How can I create a data.frame and a 3D plot of (i,x(i),y(i)), i.e. for
each iteration
Thanks,
Serguei Kaniovski
--
___________________________________________________________________
??sterreichisches Institut f??r Wirtschaftsforschung (WIFO)
Name: Serguei Kaniovski
2008 Dec 24
1
Implementing a linear restriction in lm()
Dear All!
I want to test a coeffcient restriction beta=1 in a univariate model lm
(y~x). Entering
lm((y-x)~1) does not help since anova test requires the same dependent
variable. What is the right way to proceed?
Thank you for your help and marry xmas,
Serguei Kaniovski
________________________________________
Austrian Institute of Economic Research (WIFO)
2006 Oct 03
1
Reshape into a contingency table/Fisher's test
Dear all,
how can I "reshape"/"cast" the following matrix
00;01;10;11
John.Mike;123;313;12;31
John.Jim;54;57;39;36
John.Steve;135;47;47;74
Mike.Jim;63;37;27;16
Mike.Steve;15;15;5;61
Jim.Steve;6;10;34;35
into a set of stacked 2x2 contingency tables
0;1
John;123;12
Mike;313;31
John;54;39
Jim;57;36
John;135;47
Steve;47;16
...
so that the "fisher.test" and
2007 Dec 05
1
Information criteria for kmeans
Hello,
how is, for example, the Schwarz criterion is defined for kmeans? It should
be something like:
k <- 2
vars <- 4
nobs <- 100
dat <- rbind(matrix(rnorm(nobs, sd = 0.3), ncol = vars),
matrix(rnorm(nobs, mean = 1, sd = 0.3), ncol = vars))
colnames(dat) <- paste("var",1:4)
(cl <- kmeans(dat, k))
schwarz <- sum(cl$withinss)+ vars*k*log(nobs)
Thanks
2006 Dec 04
1
Count cases by indicator
Hi,
In the data below, "case" represents cases, "x" binary states. Each
"case" has exactly 9 "x", ie is a binary vector of length 9.
There are 2^9=512 possible combinations of binary states in a given
"case", ie 512 possible vectors. I generate these in the order of the
decimals the vectors represent, as:
2008 Jan 29
1
Correlation matrix for data in long format
Hello,
I cannot figure out how to use "tapply" to compute the correlation matrix
in the variable "x" between the states? The data is in long format, e.g.:
state,year,x
Alabama,2001,0.45
Alabama,2002,0.47
Alabama,2003,0.48
Alabama,2004,0.44
Arizona,2001,0.34
Arizona,2002,0.32
Arizona,2003,0.38
Arizona,2004,0.36
Thank you in advance for your help,
Serguei Kaniovski
2005 Dec 03
1
Correlation matrix from a vector of pairwise correlations
I've a vector of pairwise correlations in the order low-index element
precedes the high-index element, say:
corr(1,2)=0.1, corr(1,3)=0.2, corr(2,3)=0.3, corr(3,4)=0.4
How can I construct the corresponding correlation matrix?
I tried using the "combn"-function in "combinat" package:
library(combinat)
combn(c(0.1,0.2,0.3,0.4),2)
, but to no avail...
Thank you for your
2008 Jan 14
2
Permutations of variables in a dataframe
Hallo All,
I would like to apply a function to all permutations of variables in a
dataframe (except the first). What is the best way to achieve this?
I produce the permutations using:
nvar <- ncol(dat) - 1
perms <- as.matrix( expand.grid(rep( list(1:0) , nvar ))[ , nvar:1] )
Thanks in advance
Serguei
Test-dataframe, comma-delimited:
code,wav,w,area,gdp,def,pop,coast,milspend,agr
2005 Dec 05
5
What is wrong with this FOR-loop?
Hi, I have a more complex example, but the problem boils down to this
FOR-loop not filling in the res-matrix
run_rows<-seq(0,1,0.05)
run_cols<-seq(0.3,0.6,0.05)
res<-matrix(NA,length(run_rows),length(run_cols))
for(i in run_rows)
{
for(j in run_cols)
{
res[i,j]=i+j
#niether the above, nor res[[i,j]]=i+j work, why?
}
}
Thank you,
Serguei
2007 Dec 04
3
Inserting a subsequence between values of a vector
Hallo,
suppose I have a vector:
x <- c(1,1,1,2,2,3,3,3,3,3,4)
How can I generate a vector/sequence in which a fixed number of zeroes (say
3) is inserted between the consecutive values, so I get
1,1,1,0,0,0,2,2,0,0,0,3,3,3,3,3,0,0,0,4
thanks a lot,
Serguei
[[alternative HTML version deleted]]
2007 Feb 22
4
Sorting rows of a binary matrix
Hallo,
The command:
x <- 3
mat <- as.matrix(expand.grid(rep(list(0:1), x)))
generates a matrix with 2^x columns containing the binary representations
of the decimals from 0 to (2^x-1), here from 0 to 7. But the rows are not
sorted in this order.
How can sort the rows the ascending order of the decimals they represent,
preferably without a function which converts binaries to decimals