[R] A combinatorial task. How to get rid of loops

2007-08-02 Thread Serguei Kaniovski
you very much for your help! Serguei Kaniovski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self

[R] Quick question on Cochran-Mantel-Haenszel test

2007-03-06 Thread Serguei Kaniovski
Dear List, I am looking for what B.S.Everitt refers to as Cochrane Method for testing independence in combined 2x2 contingency tables. Is it the same method as the Cochran-Mantel-Haenszel Chi-Squared Test for Count Data in R? Thanks, Serguei [[alternative HTML version deleted]]

[R] The plot of qqmath

2007-03-06 Thread Serguei Kaniovski
Hello, I would like to inlude the Q-Q plot by qqmath into a panel with other plots, say, using par(mfrow=c(1,2)). How can this be done given that qqmath refreshes the plotting window and there seems to be no series coming out of it? Thanks Serguei [[alternative HTML version deleted]]

[R] How to put the dependent variable in GLM proportion model

2007-02-27 Thread Serguei Kaniovski
Hello everyone, I am confused about how the dependent variable should be specified, e.g. say S and F denote series of successes and failures. Is it share-S/(S+F) glm(share~x,family=quasibinomial) or glm(cbind(S,F)~x,family=quasibinomial) The two variants produce very different dispersion

[R] Add-up duplicates and merge

2007-02-26 Thread Serguei Kaniovski
Hello, a have two matrices of data as below. I would like to add-up the duplicate in terms of pair of names in rows, and then merge the values in the second matrix to the pairs as two new variables x3 and x4. Input ,x1,x2 jane.mike,31,43 jane.steve,32,2 jane.steve,5,3 jim.mike,76,5

[R] Adding duplicates by rows

2007-02-26 Thread Serguei Kaniovski
___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail: [EMAIL PROTECTED] A-1030 Wien

[R] Overdispersion in a GLM binomial model

2007-02-25 Thread Serguei Kaniovski
Hello, The share of concurring votes (i.e. yes-yes and no-no) in total votes between a pair of voters is a function of their ideological distance (index continuous on [1,2]). I show by other means that the votes typically are highly positively correlated (with an average c=0.6). This is because

[R] how to use apply with two variables

2007-02-23 Thread Serguei Kaniovski
Hi, this is a made-up example. Function myfun returns two arguments. Can apply be used so that myfun is called only once? Thanks Serguei mat-matrix(runif(50),nrow=10,ncol=5) myfun-function(x) { mymean-mean(x) mysd-sd(x) return(mymean,mysd) } out1-t(apply(mat,1,function(x)

[R] Sorting rows of a binary matrix

2007-02-22 Thread Serguei Kaniovski
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

[R] simple question on intervals

2007-02-14 Thread Serguei Kaniovski
Hi, I have a number (correlation coefficient) x in [-1,1], and a color palette col-grey(1:N/N) for a given N. I want to assign a color from col to x which corresponds to x in levels of cut(-1:1,N). So for N-4 and x-0.3, the color should be col[3]. For N-4 and x--0.8, the color should be

[R] Colouring the polygons, correlation matrix

2007-02-12 Thread Serguei Kaniovski
which will make the colouring consistent with that in the legend. Can you help? The number of different colours is given by the parameter dens. Thanks, Serguei Kaniovski #--FUNC. CORR. PLOT cor.plot-function(mat, dens, ticks, main=) { n-dim(mat)[1] m-dim(mat)[2] N-ifelse(dens10,10,dens

[R] Error handling with try function

2007-02-09 Thread Serguei Kaniovski
message as a string and turns into a matrix of strings. Instead, I want NA in the output matrix each time an error in optim occurs. I thought try() would handle this? What's the best way of doing this? Thanks, Serguei Kaniovski [[alternative HTML version deleted

[R] fill-in a table of pairs

2007-02-07 Thread Serguei Kaniovski
Hallo, I have a table of names and values: joe 0.45 mike 0.34 jim 0.25 I would like to fill-in a table of all pairs of names (which I aleady have) joe.mike NA NA joe.jim NA NA mike.jim NA NA with the values from the first table in the order of the pairs. The outcome looks like joe.mike 0.45

[R] Questions on counts by case

2007-02-06 Thread Serguei Kaniovski
in 3 groups. Thanks a lot, Serguei Kaniovski The data looks like: person;gr;x mike;gr1;1 jane;gr1;0 bill;gr1;0 jack;gr2;1 mike;gr2;1 jane;gr2;0 bill;gr2;0 alex;gr2;1 james;gr2;1 mike;gr3;0 bill;gr3;1 jane;gr3;1

[R] Delete all dimnames

2006-12-14 Thread Serguei Kaniovski
___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail: [EMAIL PROTECTED] A-1030 Wien http://www.wifo.ac.at

[R] Count cases by indicator

2006-12-04 Thread Serguei Kaniovski
/0499;1 093/0499;1 093/0499;1 093/0499;1 093/0499;1 093/0499;1 093/0499;1 -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt

[R] A different contingency table of counts by case

2006-12-01 Thread Serguei Kaniovski
Dear All, the following code, by courtesy of Jacques VESLOT, collates the following contingency table from DATA (read in as df, sample listed below) led represents (court) cases, jid the (justices) persons, and vote is the binary state. The command: smat-t(apply(combinations(nlevels(df$jid),

[R] Solving a maximization problem using QUADPROD

2006-11-08 Thread Serguei Kaniovski
Hello, here is an example from the manual. How to turn this minimization problem into maximization problem, i.e. -(0 5 0) %*% b - 1/2 b^T b? # Assume we want to minimize: -(0 5 0) %*% b + 1/2 b^T b # under the constraints: A^T b = b0 # with b0 = (-8,2,0)^T # and (-4 2 0) # A = (-3 1 -2) # ( 0 0

Re: [R] How to best divide table by table

2006-10-28 Thread Serguei Kaniovski
For example, year X1958 X1973 X1981 X1986 X1995 X2004 X2007 1 QMT 12 41 45 54 62 232 255 2 Belgium 2 5 5 5 5 12 12 3 France 4 10 10 10 10 29 29 year X1958 X1973 X1981 X1986 X1995 X2004 X2007 1 QMT 12 41 45 54 62 232 255 2 Belgium 9054483 9741700 9859000 9859000 10137000 10418000 10497000 3

[R] Coefficients of a 2-argument generating function

2006-10-27 Thread Serguei Kaniovski
How can I, starting from a vector v[1:n], efficiently compute the coefficients of a 2-argument generating function: (1+x^v[1]*y)*(1+x^v[2]*y)*...*(1+x^v[n]*y) and put them in a matrix. Thanks, Serguei Kaniovski -- ___ Austrian

[R] How to best divide table by table

2006-10-27 Thread Serguei Kaniovski
Hi all, how can I divide two tables of the same dimension so that all names are preserved, ie do not become NA? I have tab1 and tab2, each having names in the first column. I want tab3 with the same names and values tab1/tab2. Thanks, Serguei __

[R] Fill a matrix with vectors of different lengths

2006-10-16 Thread Serguei Kaniovski
-- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail: [EMAIL PROTECTED] http://www.wifo.ac.at/Serguei.Kaniovski

[R] Coefficients of a factorized polynomial

2006-10-09 Thread Serguei Kaniovski
Hi all, starting from a vector v[1:n] I would like to compute the coefficients of the polynomial (1+x^v[1])*(1+x^v[2])*...*(1+x^v[n]). The following code works but is extremely slow for a large n due to, I believe, the polynomial being factorized. I wanted to try the package polynom command

[R] Optim: Function definition

2006-10-04 Thread Serguei Kaniovski
(sval,obj, method=BFGS)$par Thank you, Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386

[R] Reshape into a contingency table/Fisher's test

2006-10-03 Thread Serguei Kaniovski
, Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail

[R] Simple question on a function

2006-10-02 Thread Serguei Kaniovski
. Thanks a lot, Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103

[R] Compiling a contingency table of counts by case

2006-09-22 Thread Serguei Kaniovski
, b. the first has x=0 - the second has x=1, c. the first has x=1 - the second has x=0, d. both have x=0, The difficulty is that the number of names and their identity changes from case to case. Thanks a lot for you help, Serguei Kaniovski

Re: [R] Compiling a contingency table of counts by case

2006-09-22 Thread Serguei Kaniovski
Thanks Jacques, this works! Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386

[R] A contingency table of counts by case

2006-07-18 Thread Serguei Kaniovski
. the first has 0 - the second has 1, c. the first has 0 - the second has 0, d. both have 0. There will be choose(9,2) sums, denoted s_ij for 1=ij=9, where i and j are running indices for an id-pair. Please help, this is way beyond my knowledge of R! Thank you, Serguei Kaniovski

[R] Two quick questions

2006-03-02 Thread Serguei Kaniovski
collapse (sum) var1 var2 var3, by(date sector). Thank you, Serguei Kaniovski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

[R] Help on a matrix task

2005-12-06 Thread Serguei Kaniovski
Hello, Being new to R, I am completely stuck with the following problem. Please help to find a general solution to the following matrix task: Given: N-4 input_mat-matrix(c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,

[R] What is wrong with this FOR-loop?

2005-12-05 Thread Serguei Kaniovski
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

[R] Construct a data.frame in a FOR-loop

2005-12-04 Thread Serguei Kaniovski
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

[R] Correlation matrix from a vector of pairwise correlations

2005-12-03 Thread Serguei Kaniovski
(combinat) combn(c(0.1,0.2,0.3,0.4),2) , but to no avail... Thank you for your help, Serguei Kaniovski -- ___ Österreichisches Institut für Wirtschaftsforschung (WIFO) Name: Serguei Kaniovski Postadresse: Postfach 91 Tel

[R] Constraints in Quadprog

2005-11-29 Thread Serguei Kaniovski
, bvec, meq=0, factorized=FALSE) reads contraints using an element-by-element multiplication, i.e. Amat'*x, not using the matrix-product, i.e. Amat'%*%x, required for the sums on the left-hand-side of 1-6). I would very much appreciate a suggestion on this problem. Thank you, Serguei Kaniovski

[R] vector of permutated products

2005-11-23 Thread Serguei Kaniovski
to simplify the above code? Thank you in advance, Serguei Kaniovski -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-243 Arsenal Objekt 20 Fax: +43

[R] the matrix of rows with specific row sums

2005-11-22 Thread Serguei Kaniovski
one such row. Serguei Kaniovski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html