similar to: A faster way to calculate Trace?

Displaying 20 results from an estimated 3000 matches similar to: "A faster way to calculate Trace?"

2007 Sep 03
3
element wise opertation between a vector and a list
I want to try to get a result of element wise addition between a vector and a list. It can be done with "for statement." In order to reducing computing time, I have tried to avoid "for state." If anybody give me an idea, I would apprecite it much. for example, with a & b as below lines, a<- list(c(1,3),c(1,2),c(2,3)) b<-c(10,20,30) I would like to have a list (like
2006 Nov 15
2
Sparse matrix calculation
Hello, I work on large matrices and found something interesting. For multiplication of matrices, the order has a huge influence on computing time when one of them is a sparse matrix. In the below example, M is a full matrix and A is a sparse matrix in a regular matrix class. A %*% M takes much more time than M %*% A; moreover, t(t(M) %*% t(A)) is much faster than A %*% M with same result. I
2006 Nov 14
2
Building R from source
Hello, I was trying to build R from source on Windows XP. I installed software which are mentioned from the follow web page http://www.murdoch-sutherland.com/Rtools/ (Last accessed on Nov. 13th, 2006) . Unfortunately, I got error messages whenever I run 'make all recommended' without modifying 'MkRules' file. I have removed software and reinstalled them several times but I still
2004 Jan 26
1
Question about design matrix
Now, I am working with some design matrices. My problem is to set "contrasts" option. Now I want to use "contr.sum" as the option, and it works properly. However, this option sets the last element of a factor as -1. For example, if I have a factor which has 5 elements and want to use the "contr.sum" option, the 5th elements is always set to -1. I want set -1 to other
2005 Jun 24
1
lme4 extracting individual variance components
Hi, For further calculations I need to extract indivdual Variances of different random effects from a fitted model. I found out how to extract the correlations (VarCorr(m1)@reSumry$group1) but I was not able to find a way to extract the other components individually. To extract the Residuals I tried: (ranef(m1)@ stdErr) which unfortunately did not work. Thank you very much for your help!
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)") #
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 <-
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:
2010 Oct 08
3
Efficiency Question - Nested lapply or nested for loop
My data looks like this: > data name G_hat_0_0 G_hat_1_0 G_hat_2_0 G_0 G_hat_0_1 G_hat_1_1 G_hat_2_1 G_1 1 rs0 0.488000 0.448625 0.063375 1 0.480875 0.454500 0.064625 1 2 rs1 0.002375 0.955375 0.042250 1 0.000000 0.062875 0.937125 2 3 rs2 0.050375 0.835875 0.113750 1 0.877250 0.115875 0.006875 0 4 rs3 0.000000 0.074750 0.925250 2 0.897750 0.102000
2008 Jul 03
1
lm() question
I have data that looks like YC Age Num 82 11 2 83 10 0 84 9 8 85 8 21 86 7 49 87 6 18 88 5 79 89 4 28 90 3 273 91 2 175 with a program mod1=lm(log(Num+1)~YC, data=box44) plot(log(Num+1)~YC, data=box44, pch=19, xlab="Year Class", ylab="Loge Number at age", ylim=c(0,6), xlim=c(91,82)) abline(lm(log(Num+1)~YC), col="blue", lwd=2) summary(mod1) I need to
2005 Dec 03
2
How to catch value
Dear R users: I have a problem about catch the value from function. I have following two functions (part): fbolus1 <- function() {......... par<-data.frame(Parameter=c("kel","Vd"),Initial=c(0)) check(par) .....} check<-function(par) { if (par[ ,2] <= 0){ cat("\nEnter again (y/n) ?\n\n") ans<-readline() if (ans == "n" ){
2009 Mar 12
8
help with loop
Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this:   c <- list()   for(i in 1:ncol(mydata)) {   for(j in 2:nrow(mydata)) {   c[[i]] <- sum(yc[j,i] - yc[(j-1),i])   }}} As for the columns it works pretty fine, but it only
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,
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
2011 May 10
1
Scale time series in a way that 90% of the data is in the -0.-9/ +0.9 range
Hello, please excuse my ignorance as i am new to R and this might seem trivial to you How can i scale my time series in a way that 90% of the data is in the -0.-9/ +0.9 range? I think i first have to select the 90% closest to the mean and then calculate my scaling parameter on it, then scale the whole series. I think i could use outlier() from outliers package to identify the outer 10%,
2002 Nov 27
6
"attrib +R myowndir" fails to write-protect my own dir
A trivial case: executing the following DOS command from the prompt line on a Win2K SP3: %windir%\system32\attrib.exe +R H:\dir can't set the R(eadonly) flag on my home dirs (2.2.7): drwxrwsr-x 4 me users 4096 Nov 27 17:59 . drwxr-sr-x 2 me users 4096 Nov 27 17:59 dir -r--r--r-- 1 me users 0 Nov 27 17:59 empty.txt drwxr-sr-x 2 me users 4096 Nov 27 17:27
2002 Oct 29
1
samba compiling error
Hello, I have error on compiling time I tried on HP-UX 11.00 system with gcc version 3.1 to compile samba source Samba latest version source was dowloaded from www.us1.samba.org/samba/ftp I attached log file with this error thank you. begin 600 samba_make.log.doc M(R!M86ME#0HO=7-R+VQO8V%L+W-A;6)A+V)I;B(@+410241$25(](B]U<W(O M;&]C86PO<V%M8F$O=F%R+VQO8VMS(B
2017 Oct 22
2
Syntax for fit.contrast
I have a model (run with glm) that has a factor, type. Type has two levels, "general" and "regional". I am trying to get estimates (and SEs) for the model with type="general" and type ="regional" using fit.contrast but I can't get the syntax of the coefficients to use in fit.contrast correct. I hope someone can show me how to use fit.contrast, or some
2006 Aug 04
1
Integration and Loop in R
Dear All, I have seldom needed to use loops in R, but now I need to code a loop with a stride different from one. In the R manual I downloaded I have the example: > xc <- split(x, ind) > yc <- split(y, ind) > for (i in 1:length(yc)) { plot(xc[[i]], yc[[i]]); abline(lsfit(xc[[i]], yc[[i]])) } but in my case I'd like to add a condition so that i varies by 4 from one go