search for: covmat

Displaying 20 results from an estimated 64 matches for "covmat".

2009 May 09
2
Sweave \Sexpr{} advice please
...tly. A question in my work I use \Sexpr{} statements scalar values and the xtable package for all manner of tables. What I'd like to do is to use a vector inline, rather than a whole separate table. Something like: %%%%%%%%%%%%%%%% begin code % Latex junk % Sweave block: <<>>= covmat <- cov(matrix(runif(100),ncol=3)) @ % back to Latex, typing up a report, my homework, etc. The first column of the covariance matrix is $(\Sexpr{covmat[1,1]}, \Sexpr{covmat[2,1]}, \Sexpr{covmat[3,1]})^T$ %%%%%%%%%%%%%%%%% end code but, of course, this is poor way of going about it. Any sugge...
2011 Oct 18
1
Repeat a loop until...
...I know there have been various questions posted over the years about loops but I'm afraid that I'm still stuck. I am using Windows XP and R 2.9.2. I am generating some data using the multivariate normal distribution (within the 'mnormt' package). [The numerical values of sanad and covmat are not important.] > datamat <- rmnorm(n=1500,mean=c(mean(sanad[,1]),mean(sanad[,2]),mean(sanad[,3])),varcov=covmat) The middle column of 'datamat' is simulated data for age. Obviously some of the simulated values are not going to be sensible. Therefore I'd like to set up a fu...
2007 Feb 06
3
How-To construct a cov list to use a covariance matrix in factanal?
...h includes the cov, the centers, and the n.obs. But it doesn't work. I get an error that says "Error in sqrt(diag(cv)) : Non-numeric argument to mathematical function". So, obviously I am doing something wrong. Two questions occur. Can someone either tell me how to construct a proper covmat list object or point me to a description of how to do it? The other question is whether it is possible to simply use the covariance matrix as the argument for covmat in factanal? The description implies that it is but I really have no idea of how to do this. I have tried simply making covmat the co...
2008 Oct 09
2
vectorization instead of using loop
...n x. In other words, we want to create a n x n matrix with distances (with zeros in the diagonal). However, we do not want to calculate Euclidian distances. We want to calculate Mahalanobis distances, which take into account the covariance among variables. Below is the piece of code we wrote ("covmat" in the function below is the variance-covariance matrix among variables in Data that has to be fed into mahalonobis function we are using). mahadist = function(x, covmat) { dismat = matrix(0,ncol=nrow(x),nrow=nrow(x)) for (i in 1:nrow(x)) { dismat[i,] = mahalanobis(as.matrix(x), as....
2003 Aug 08
1
covmat argument in princomp() (PR#3682)
R version: 1.7.1 OS: Red Hat Linux 7.2 When "covmat" is supplied in princomp(), the output value "center" is all NA's, even though the input matrix was indeed centered. I haven't read anything about this in the help file for princomp(). See code below for an example: pc2$center is all NA's. Jerome Asselin x <- rnor...
2005 Jun 26
0
Factor correlations in factanal
...- snip------------ # modifications by J. Fox, 26 June 2005 marked in source ## Hmm, MM thinks diag(.) needs checking { diag(vec) when length(vec)==1 !} ## However, MM does not understand that factor analysis ## is a *multi*variate technique! factanal <- function (x, factors, data = NULL, covmat = NULL, n.obs = NA, subset, na.action, start = NULL, scores = c("none", "regression", "Bartlett"), rotation = "varimax", control = NULL, ...) { sortLoadings <- function(Lambda) { cn &l...
2008 Sep 09
1
Addendum to wishlist bug report #10931 (factanal) (PR#12754)
...General Public License is available at # http://www.r-project.org/Licenses/ ## Hmm, MM thinks diag(.) needs checking { diag(vec) when length(vec)==1 !} ## However, MM does not understand that factor analysis ## is a *multi*variate technique! factanal <- function (x, factors, data = NULL, covmat = NULL, n.obs = NA, subset, na.action, start = NULL, scores = c("none", "regression", "Bartlett"), rotation = "varimax", control = NULL, ...) { sortLoadings <- function(Lambda) { cn &l...
2009 Jan 30
1
Factor Analysis-factanal function
Dear friends, I'm using R to produce the following Factor Analysis: > matriz.cor<-hetcor(matrix(as.factor(data), ncol=variables, byrow=T))$correlations > factanal(x=data, factors=2, covmat=matriz.cor, scores='regression') Then the screen output shows the following message: Error en factanal(x = data, factors = 2, covmat = matrix, : requested scores without an 'x' matrix Do you know some additional function in order to produce a matrix of scores when ...
2012 Sep 17
2
Constraint Optimization with constrOptim
Hi, I am having trouble using constrOptim. My target is to do a portfolio optimization and there some constraints have to be fulfilled. 1) The weight of each share of the portfolio has to be greater than 0 2) The sum of these weights has to be 1 I am able to fulfill either the first or the second constraint but not both. One simple way would be to fulfill the first constraint by using optim as
2004 Nov 16
5
Difference between two correlation matrices
Hi Now a more theoretical question. I have two correlation matrices - one of a set of variables under a particular condition, the other of the same set of variables under a different condition. Is there a statistical test I can use to see if these correlation matrices are "different"? Thanks Mick
2002 Aug 29
2
Factor Analysis in MASS4
Hi, I had a look at the MASS4 scripts in the MASS package, in Ch 11.3 Factor Analysis, there is a section of codes like: data(ability.cov) ability.FA <- factanal(covmat = ability.cov, factors = 1) ability.FA (ability.FA <- update(ability.FA, factors = 2)) #summary(ability.FA) round(loadings(ability.FA) %*% t(loadings(ability.FA)) + diag(ability.FA$uniq), 3) Unfortunately I still haven't received the book I ordered, so I can't look...
1997 Apr 30
1
R-beta: ls.print
ls.print produces error that I don't seem to be able to trace. Output of the commands as follows: (hyeung is a 24x2 matrix of data) ------------------------------------------------- > summary(hyeung) x.1 x.2 Min. : 28.0 Min. : 10.0 1st Qu.: 72.0 1st Qu.: 87.5 Median : 86.5 Median : 92.5 Mean : 81.0 Mean : 82.5 3rd Qu.: 97.0 3rd Qu.:100.0 Max.
1997 Apr 30
1
R-beta: ls.print
ls.print produces error that I don't seem to be able to trace. Output of the commands as follows: (hyeung is a 24x2 matrix of data) ------------------------------------------------- > summary(hyeung) x.1 x.2 Min. : 28.0 Min. : 10.0 1st Qu.: 72.0 1st Qu.: 87.5 Median : 86.5 Median : 92.5 Mean : 81.0 Mean : 82.5 3rd Qu.: 97.0 3rd Qu.:100.0 Max.
2007 Nov 28
1
Power model in R
Um texto embutido e sem conjunto de caracteres especificado associado... Nome: n?o dispon?vel Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071128/0d193362/attachment.pl
2012 May 28
3
Factanal fits
Greetings, all: I am using factanal in R. When I enter a matrix or a formula, the print method winds up with something like this: Test of the hypothesis that 6 factors are sufficient. The chi square statistic is 28.1 on 22 degrees of freedom. The p-value is 0.172 But when I enter a covmat, the print method winds up with something like this: The degrees of freedom for the model is 22 and the fit was 0.0904 The actual factanal print method is suppressed, so I can't figure out how the two calculations are done, or how they relate to one another. Can any of you help? Many thanks...
2007 May 19
2
What's wrong with my code ?
...- 0.5*factors/p)/diag(solve(cmat)) res <- optim(start, FAfn, FAgr, method="L-BFGS-B", lower = lower, upper = 1, control = c(list(fnscale=1, parscale = rep(0.01, length(start))), control), q = factors, S = cmat) res } covmat <- structure(c(1, 0.0920030858518061, 0.053952442382614, -0.0380048634941013, 0.237986469993129, 0.243144461077282, 0.0920030858518061, 1, 0.328163804480881, 0.142002180914605, -0.139369611642031, -0.0670944471678571, 0.053952442382614, 0.328163804480881, 1, 0.267648727315665, -0.054998750815744...
2006 Jun 20
2
glm beta hypothesis testing
In summary.glm I'm trying to get a better feel for the z output. The following lines can be found in the function 1 if (p > 0) { 2 p1 <- 1:p 3 Qr <- object$qr 4 coef.p <- object$coefficients[Qr$pivot[p1]] 5 covmat.unscaled <- chol2inv(Qr$qr[p1, p1, drop = FALSE]) 6 dimnames(covmat.unscaled) <- list(names(coef.p), names(coef.p)) 7 covmat <- dispersion * covmat.unscaled 8 var.cf <- diag(covmat) 9 s.err <- sqrt(var.cf) 10 tvalue <- coef.p/s.err 11 dn...
2000 Jun 19
1
outer problem
why does teh following code not work? a<-rnorm(50) dim(a)<-c(10,5) mycov<-function(mat,i,j){ sum((mat[,i]-mean(mat[,i]))*(mat[,j]-mean(mat[,j]))) } covmat<-function(X){ outer(1:dim(X)[2],1:dim(X)[2],function(v1,v2){mycov(X,v1,v2)})} from what i know covmat(a) should give the covariance matrix of a, but it gives a matrix with constant elements. mycov(a,1,2) ans simlar calls are doing the right thing. so somehow i am misunderstanding oute...
2006 Jul 16
1
Manipulation involving arrays
...In particular, I would like to replace the nested "for" loop with a faster construct. I tried things like "kronecker" and "outer" combined with apply, but couldn't get it to work. Here is a sample code: ########################## n <- 120 sigerr <- 5 covmat <- diag(c(8,6,3.5)) mu <- c(105,12,10) mcsamp <- 10000 Tbar <- array(0, dim=c(3,3,n)) # theta is a mcsamp x 3 matrix theta <- mvrnorm(mcsamp, mu = mu, Sigma = covmat) wt <- matrix(runif(n*mcsamp),n,mcsamp) wti <- apply(wt,1,sum) tarray <- array(apply(theta,1...
2011 Jun 11
2
Factor Analysis/Inputting Correlation Matrix
Can someone please direct me to how to run a factor analysis in R by first inputting a correlation matrix? Does the function "factanal" allow one to read a correlation matrix instead of data vectors? Thanks, Matt. [[alternative HTML version deleted]]