search for: cmat

Displaying 20 results from an estimated 55 matches for "cmat".

Did you mean: cat
2007 Nov 22
2
Vectorize a correlation matrix
Hello I can construct a correlation matrix from an (ordered) vector of correlation coefficients as follows: x <- c(0.1,0.2,0.3,0.4,0.5) n <- length(x) cmat <- diag(rep(0.5,n)) cmat[lower.tri(cmat,diag=0)] <- x cmat <- cmat+t(cmat) But how to do the reverse operation, i.e. produce x from cmat? Thanks for help, Serguei Kaniovski [[alternative HTML version deleted]]
2005 Apr 21
1
printCoefmat(signif.legend =FALSE) (PR#7802)
printCoefmat(signif.legend =FALSE) does not work properly. The option "signif.legend = FALSE" is ignored as shown in the example below. cmat <- cbind(rnorm(3, 10), sqrt(rchisq(3, 12))) cmat <- cbind(cmat, cmat[,1]/cmat[,2]) cmat <- cbind(cmat, 2*pnorm(-cmat[,3])) colnames(cmat) <- c("Estimate", "Std.Err", "Z value", "Pr(>z)") # Prints the legend, although it should not printCoefma...
2002 Apr 09
1
Problem handling NA indexes for character matrixes (PR#1447)
In a package I've been developing for manipulating genetic data I discovered a problem when indexing into character arrays using NA's: Create a character matrix and a numeric matrix > cmat <- matrix( letters[1:4], ncol=2, nrow=2) > nmat <- matrix( 1:4, ncol=2, nrow=2) Create an index vector containing an NA value > indvec <- c(1,2,NA) Indexing works fine for both matrixes when we only pull off *one* column: > cmat[ indvec, 1 ] [1] "a" "b&quot...
2006 Dec 04
1
Count cases by indicator
...t;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: cmat<-as.matrix(expand.grid(rep(list(0:1),9))) cmat<-cmat[nrow(cmat):1,ncol(cmat):1] "cmat" contains the binary vectors as rows. QUESTION: I would like to know how often each of the 512 vectors occurs in "case". With these data, the output should be a vector with 2^9=512 co...
2007 May 19
2
What's wrong with my code ?
I try to code the ULS factor analysis descrbied in ftp://ftp.spss.com/pub/spss/statistics/spss/algorithms/ factor.pdf # see PP5-6 factanal.fit.uls <- function(cmat, factors, start=NULL, lower = 0.005, control = NULL, ...) { FAfn <- function(Psi, S, q) { Sstar <- S - diag(Psi) E <- eigen(Sstar, symmetric = TRUE, only.values = TRUE) e <- E$values[-(1:q)] e <- sum(e^2/2) e } FAgr <- function(Psi, S, q) { Sstar...
2008 Apr 29
0
Looking for Post-hoc tests (a la TukeyHSD) or interaction-level independent contrasts for survival analysis.
...esponsible tack would be to clearly define the contrasts I'd like to make within the interaction term. However this has yet to work as fully as I'd like it. I've successfully set the contrasts matrix for the three-level factor "Group" following Crawley's The R Book. cmat<-cbind(c(-1,1,0),c(0,-1,1)) contrasts(subb$Group)<-cmat contrasts(subb$Group) By setting these contrasts and then looking at the interaction terms in the coxph model, this allows me to compare groups _within_ each separate treatment, and confirms both that #2) that groups 1 and 2 are not...
2010 Oct 08
3
Efficiency Question - Nested lapply or nested for loop
...atrix index of the first row and second column. (Note that the ranges between rows and columns are one off. That is accounted for in the code.) In reality the data will be much bigger, containing 10000 rows and a variable number of columns (inds) between 10 and 500. The correct result is: > cmat tru_rr tru_rv tru_vv call_rr 2 2 0 call_rv 0 4 0 call_vv 0 0 4 I am not sure what the best way to do this is. I implemented it once using two for loops. Then I tried to use lapply and came up with a nested lapply solution, but it was slower t...
2008 Nov 21
2
Extracting diagonal matrix
Dear All, I have a correlation matrix of size 100 x 100 and would like to extract the diagonal matrix from it. I have used the for loop to store tha correlation values of the diagonal matrix. Is there a 'R way' of doing this? Thanks in advance. Kind regards, Ezhil
2005 Jun 26
0
Factor correlations in factanal
...fit$STATISTIC <- (n.obs - 1 - (2 * p + 5)/6 - (2 * factors)/3) * fit$criteria["objective"] fit$PVAL <- pchisq(fit$STATISTIC, dof, lower.tail = FALSE) } fit$n.obs <- n.obs fit$call <- cl fit } factanal.fit.mle <- function(cmat, factors, start=NULL, lower = 0.005, control = NULL, ...) { FAout <- function(Psi, S, q) { sc <- diag(1/sqrt(Psi)) Sstar <- sc %*% S %*% sc E <- eigen(Sstar, symmetric = TRUE) L <- E$vectors[, 1:q, drop = FALSE] load <- L %*% diag(sq...
2002 Mar 06
2
Announce: R from Python
...he code of RSPython, but modifying it a little, I wrote an interface for using R from Python. The main reason for writing it was to make it robust, in order to avoid segmentation faults. Also, it is (IMMO) a very transparent interface between Python and R. It is downloadable from http://www.cmat.edu.uy/~walterm/rpy I attach a fragment of the README. Regards: Walter -- -------------- Walter Moreira <> Centro de Matematica <> Universidad de la Republica email: walterm at cmat.edu.uy <> Home Page: http://www.cmat.edu.uy/~walterm RPy 0.1 - Python interfa...
2017 Oct 22
2
Syntax for fit.contrast
...> levels(data$type) [1] "general" "regional" > contrasts(data$type) regional general 0 regional 1 I have tried the following syntax for fit.contrast fit.contrast(model,type,c(1,0)) and get an error: Error in `[[<-`(`*tmp*`, varname, value = cmat) : no such index at level 1 > fit.contrast(model,type,c(0,1),showall=TRUE) and get an error: Error in `[[<-`(`*tmp*`, varname, value = cmat) : no such index at level 1 > fit.contrast(model,type,c(1,-1),showall=TRUE) and get an error: Error in `[[<-`(`*tmp*`, varname, value = cm...
2009 Jul 10
1
problems with contrast matrix
...model: model1<-lmer(PE~Sex+LightIntensity+ordered(WA)+(1|Animal),data=datamic,na.action=na.omit,family="poisson",REML=FALSE) model2<-lme(LA~Sex+LightIntensity+ordered(WA),random=~1|Animal,data=datamic,na.action=na.omit,method="ML") So I built a specific contrast matrix: cmat.r<-matrix(c(-3/6,-2/6,-1/6,+1/6,+2/6,+3/6, # linear effect -3/6,+1/6,+2/6,+2/6,+1/6,-3/6, # main quadratic effect 0,0,-1/2,+1/2,0,0, # mid wavelengths 0,-1/2,0,0,+1/2,0, #intermediate wavelengths -1/2...
2009 Feb 12
3
get top 50 correlated item from a correlation matrix for each item
Hi, I have a correlation matrix of about 3000 items, i.e., a 3000*3000 matrix. For each of the 3000 items, I want to get the top 50 items that have the highest correlation with it (excluding itself) and generate a data frame with 3 columns like ("ID", "ID2", "cor"), where ID is those 3000 items each repeat 50 times, and ID2 is the top 50 correlated items with ID,
2010 Dec 06
1
use pcls to solve least square fitting with constraints
Hi, I have a least square fitting problem with linear inequality constraints. pcls seems capable of solving it so I tried it, unfortunately, it is stuck with the following error: > M <- list() > M$y = Dmat[,1] > M$X = Cmat > M$Ain = as.matrix(Amat) > M$bin = rep(0, dim(Amat)[1]) > M$p=qr.solve(as.matrix(Cmat), Dmat[,1]) > M$w = rep(1, length(M$y)) > M$C = matrix(0,0,0) > p<-pcls(M) Error in t(qr.qty(qra, t(M$X))[(j + 1):k, ]) : error in evaluating the argument 'x' in selecting a method...
2001 Aug 31
2
contrasts in lm
I've been playing around with contrasts in lm by specifying the contrasts argument. So, I want to specify a specific contrast to be tested Say: > y _ rnorm(100) > x _ cut(rnorm(100, mean=y, sd=0.25),c(-3,-1.5,0,1.5,3)) > reg _ lm(y ~ x, contrasts=list(x=c(1,0,0,-1))) > coef(reg)[2] x1 -1.814101 I was surprised to see that I get a different estimate for the
2008 Nov 24
3
Help With Permutations
...a problem with permutations functions in R I just started using R so maybe it is an easy question I need to obtain all the 9.somthingExp 157 permutations that can be given from the number from 1 to 100 I wrote the following commands: > library(gregmisc) >options(expressions=1e5) cmat <- combinations(300,2) dim(cmat) # 44850 by 2 >permutations(n=100, r=100) Unfortunately at a certain point (after few minutes) I get the following Error: Error: cannot allocate vector of size 609.1 Mb What can I do? Thanks Fabio [[alternative HTML version deleted]]
2017 Oct 22
0
Syntax for fit.contrast
...ional" > >> contrasts(data$type) > regional > general 0 > regional 1 > > > I have tried the following syntax for fit.contrast > > fit.contrast(model,type,c(1,0)) > and get an error: > Error in `[[<-`(`*tmp*`, varname, value = cmat) : > no such index at level 1 > > >> fit.contrast(model,type,c(0,1),showall=TRUE) > and get an error: > Error in `[[<-`(`*tmp*`, varname, value = cmat) : > no such index at level 1 > > > >> fit.contrast(model,type,c(1,-1),showall=TRUE) > and get a...
2009 May 26
2
Linear Regression with Constraints
Hi! I am a bit new to R. I am looking for the right function to use for a multiple regression problem of the form: y = c1 + x1 + (c2 * x2) - (c3 * x3) Where c1, c2, and c3 are the desired regression coefficients that are subject to the following constraints: 0.0 < c2 < 1.0, and 0.0 < c3 < 1.0 y, x1, x2, and x3 are observed data. I have a total of 6 rows of data in a data set. Is
2006 Mar 15
3
Help on factanal.fit.mle
Hi Can anybody please suggest me about the documentation of "factanal.fit.mle()" (Not factanal()------ searching factanal.fit.mle() in R always leads to factanal()). Is there any function for doing principal component factor analysis in R. Regards Souvik Bandyopadhyay JRF, Dept Of Statistics Calcutta University [[alternative HTML version deleted]]
2008 Sep 09
1
Addendum to wishlist bug report #10931 (factanal) (PR#12754)
...fit$STATISTIC <- (n.obs - 1 - (2 * p + 5)/6 - (2 * factors)/3) * fit$criteria["objective"] fit$PVAL <- pchisq(fit$STATISTIC, dof, lower.tail = FALSE) } fit$n.obs <- n.obs fit$call <- cl fit } factanal.fit.mle <- function(cmat, factors, start=NULL, lower = 0.005, control = NULL, ...) { FAout <- function(Psi, S, q) { sc <- diag(1/sqrt(Psi)) Sstar <- sc %*% S %*% sc E <- eigen(Sstar, symmetric = TRUE) L <- E$vectors[, 1:q, drop = FALSE] load <- L %*% diag(sq...