search for: xmat

Displaying 20 results from an estimated 33 matches for "xmat".

Did you mean: mat
2008 Aug 18
2
matrix row product and cumulative product
...ions. Thanks ?jeff > prod.matrix=function(x) + { + y=x[,1] + for(i in 2:dim(x)[2]) + y=y*x[,i] + return(y) + } > cumprod.matrix=function(x) + { + y=matrix(1,nrow=dim(x)[1],ncol=dim(x)[2]) + y[,1]=x[,1] + for (i in 2:dim(x)[2]) + y[,i]=y[,i-1]*x[,i] + return(y) + } > N=10000000 > xmat=matrix(runif(N),ncol=10) > system.time(cumprod.matrix(xmat)) user system elapsed 1.07 0.09 1.15 > system.time(t(apply(xmat,1,cumprod))) user system elapsed 29.27 0.21 29.50 > system.time(prod.matrix(xmat)) user system elapsed 0.29 0.00 0.30 > system.time(apply(xmat,1,prod)) user sys...
2005 Jul 07
3
xmat[1, 2:3] <- NULL
I have a situation where I'm filling out a dataframe from a database. Sometimes the database query doesn't get anything, so I end up trying to place NULL in the dataframe like below. > temp <- NULL > xmat <- as.data.frame(matrix(NA, 2, 3)) > xmat[1, 2:3] <- temp Error in if (m < n * p && (n * p)%%m) stop(gettextf("replacement has %d items, need %d", : missing value where TRUE/FALSE needed I can't get the programme to accept that sometimes what the query l...
2001 Mar 26
1
Item Analysis and Cronbach's Alpha (Code Attached)
...em-total correlations (corrected) and item-removed alpha. Thought some of you might find it useful. I would also appreciate any programming tips or suggestions for improving the function as I am still relatively new to R and statistical programming in general. Cheers! Alpha<- function(x){ xmat<-as.matrix(na.omit(x)) xmat.z<-scale(xmat) N<-dim(xmat)[2] Correlation.Matrix<-cor(xmat) Item.Tot.Cor<-rep(NA,N) for (a in 1:N) Item.Tot.Cor[a]<-(cor(apply(xmat[,- a],1,sum),xmat[,a])) Item.Rem.Alpha<-rep(NA,N) for (b in 1:N) Item.Rem.Alpha[b]<- ((N-1)/(N-2))...
2002 Sep 03
1
t(xmat)
Hi, I have a matrix and time series "xmat". I have no problem executing any matrix functions except t(xmat) which gives the following error message. My question if "xmat" is a matrix why I can not execute this matrix function?? converting the time series and matrix into a data frame solves the problem >dim(xmat) [1] 98 7...
2004 Sep 16
1
Newbie q. need some help understanding this code.
...el. What would help me tremendously is to see the breakdown of the line by line code into plain english. thanks for any insights or other comments. sean library(stepfun) lv <- function(N=1000,cvec=c(1,0.005,0.6),x=c(50,100)) { m<-length(cvec) n<-length(x) xmat<-matrix(nrow=N+1,ncol=n) tvec<-vector("numeric",N) h<-vector("numeric",m) t<-0 xmat[1,]<-x for (i in 1:N) { h[1]<-cvec[1]*x[1] h[2]<-cvec[2]*x[1]*x[2] h[3]<-cvec[3]*x[...
2009 Mar 05
3
methods package
...CRAN in the hopes for more there, but can't find it. Perchance there is something obvious that I am missing? 2. The changes are small but numerous. The current one that has me puzzled is a method for addition: setMethod(Ops, signature=c('numeric', 'bdsmatrix'), .... Let xmat be ordinary and bmat be a bdsmatrix. In the old code "xmat + bmat" fell to this method (which knows what to do), in the current R I get failure due to no method found. is.numeric(xmat) is TRUE. What is the fix? 3. In the green book the examples used .Dim and .Dimnames slots, the Ma...
2005 Jul 22
1
find confounder in covariates
Hi, I was wondering if there is a way, or function in R to find confounders. For istance, > a = sample( c(1:3), size=10,replace=T) > X1 = factor( c('A','B','C')[a] ) > X2 = factor( c('Aa','Bb','Cc')[a] ) > Xmat = data.frame(X1,X2,rnorm(10),rnorm(10)) > dimnames(Xmat)[[2]] = c('z1','z2','z3','y') Now, z2 is just an alias of z1. There can be a collinearity like one is a linear combination of others. If you run lm on it: > f = lm(y~.,data=Xmat) > summary(f) Call:...
2004 Sep 28
3
sapply behavior
..., either 1.8.0 or 1.9.1) Thanks for any help, Elizabeth Purdom > temp2<-matrix(sample(1:6,6,replace=F),byrow=F,nrow=6,ncol=4) > colnames(temp2)<-paste("A",as.character(1:4),sep="") > temp2<-as.data.frame(temp2) > newtemp2<-sapply((1:6),function(x){xmat<-temp2[temp2[,1]==x,,drop=F];return(xmat[1,])}) > print(newtemp2) #looks like matrix [,1] [,2] [,3] [,4] [,5] [,6] A1 1 2 3 4 5 6 A2 1 2 3 4 5 6 A3 1 2 3 4 5 6 A4 1 2 3 4 5 6 > is.matrix(newtemp2) #says it's matrix [1] T...
2007 Apr 13
3
apply problem
...s and numeric columns. It appears to convert are columns into as.character? Does it convert data.frame into matrix? Is this expected? I wish it to recognise numerical columns and round numbers. Can I use another function instead of apply, or should I use a for loop in the case? > summary(xmat) A B C D Min. : 1.0 414 : 1 Stage 2: 5 Min. :-0.075369 1st Qu.:113.8 422 : 1 Stage 3: 6 1st Qu.:-0.018102 Median :226.5 426 : 1 Stage 4:441 Median :-0.003033 Mean :226.5 436 : 1 Mean...
2004 Mar 03
1
match.call(), S4
...ect. I need to add an extra comma to get the same results as in the S3 method. --------example setClass("foo",representation("matrix")) setMethod("[", c("foo","ANY"), function(x, i, j, drop, ...) { mc <- match.call() print(mc) xmat <- x at .Data mc[[2]] <- as.name("xmat") return(eval(mc)) }) "[.bar" <- function(x, ...) { mc <- match.call() print(mc) xmat <- unclass(x) mc[[1]] <- as.name("[") mc[[2]] <- as.name("xmat") return(...
2012 Oct 27
2
Class generator functions for reference classes
As of rev. 61035 in r-devel, setRefClass() now returns a generator function, as setClass() has done since 2.15.0. The convenient style is now: mEdit <- setRefClass("mEdit",......) xx <- mEdit(data = xMat) instead of xx <- mEdit$new(data = xMat) The returned object still has fields and methods accessible as before. See the "Value" and "Reference Class Generators" sections of ?ReferenceClasses for details. Thanks to Romain Fran?ois for suggesting this. John
2008 Oct 01
0
xpred.rpart() in library(mvpart)
R-users E-mail: r-help@r-project.org Hi! R-users. http://finzi.psych.upenn.edu/R/library/mvpart/html/xpred.rpart.html says: data(car.test.frame) fit <- rpart(Mileage ~ Weight, car.test.frame) xmat <- xpred.rpart(fit) xerr <- (xmat - car.test.frame$Mileage)^2 apply(xerr, 2, sum) # cross-validated error estimate # approx same result as rel. error from printcp(fit) apply(xerr, 2, sum)/var(car.test.frame$Mileage) printcp(fit) I carried out the R object: function () { # library(mvpart)...
2020 Oct 27
3
R for-loop to add layer to lattice plot
...ainset <- trainset[, -trainColNum] testset <- testset[, -trainColNum] svm_model <- svm(z ~ ., data = trainset, type = "C-classification", kernel = "linear", scale = FALSE) # generate contour xmat = make.grid(matrix(c(testset$x, testset$y), ncol = 2, byrow=FALSE)) xgrid = as.data.frame(xmat) names(xgrid) = c("x", "y") z = predict(svm_model, xgrid) xyz_dat = as.data.frame(cbind(xgrid, z)) plot_list[[i]] = contourplot(z ~ y+x, data=xyz_da...
2005 May 20
1
using src/Makevars file
...laration of or reference to symbol `forall' at (^) [initially seen at (^)] ... ----end output ---- The code compiles using: gfortran -c estimate.f I can run my code if I build the .so by hand and then dyn.load it. Here is my F95 test code: subroutine estimate(beta, yij, nij, nxrows, nxcols,xmat, & irequest, ierror) integer nxrows, nxcols, yij, nij, irequest, ierror double precision beta(nxrows), xmat(nxrows,nxcols) integer i i = 0 c fortran 95 version forall (i = 1:nxrows) beta(i) = i * 2 ierror = 0 end Regards, Joel Bremson UC Davis [[alternative HTML version deleted]]
2002 Apr 15
2
krige and polygon limit problem
...795, 2217396, units of prediction points. Using points within c(785291, 789980, 794030, 798282, 805920, 813151, 817000, 820902, units of prediction points. Predicting.Error: (list) object cannot be coerced to vector type 14 In addition: Warning messages: 1: X matrix was collinear in: lsfit(xmat, y, wt = w, intercept = FALSE) 2: X matrix was collinear in: lsfit(xmat, y, wt = w, intercept = FALSE) 3: X matrix was collinear in: lsfit(xmat, y, wt = w, intercept = FALSE) 4: X matrix was collinear in: lsfit(xmat, y, wt = w, intercept = FALSE) ------------------------------- Do you have an...
2009 Apr 04
1
Problem with sample()
...n anyone advise me as to the possible origin of this error? Here is my code #Discretised Gillespie algorithm function (From SMfSB, D.J. Wilkinson) gillespied=function (N, T=100, dt=1, ...) { tt=0 n=T%/%dt x=N$M S=t(N$Post-N$Pre) u=nrow(S) v=ncol(S) xmat=matrix(0,ncol=u,nrow=n) i=1 target=0 repeat { h=N$h(x, ...) h0=sum(h) if (h0<1e-10) tt=1e99 else tt=tt+rexp(1,h0) while (tt>=target) { xmat[i,]=x i=i+1 target=target+dt if (i>n) return(ts(xmat,start=0,deltat=dt)) }...
2020 Oct 28
0
R for-loop to add layer to lattice plot
...t; testset <- testset[, -trainColNum] > svm_model <- svm(z ~ ., > data = trainset, > type = "C-classification", > kernel = "linear", > scale = FALSE) > # generate contour > xmat = make.grid(matrix(c(testset$x, testset$y), > ncol = 2, byrow=FALSE)) > xgrid = as.data.frame(xmat) > names(xgrid) = c("x", "y") > z = predict(svm_model, xgrid) > xyz_dat = as.data.frame(cbind(xgrid, z)) > plot_list[[i]] = co...
2007 Mar 22
2
Colored boxes with values in the box
Hi all, I have a x, y matrix of numbers (usually ranging from 0 to 40). I need to group these numbers and assign a color to each group (for example 0 to 15 - Blue, 16-30- Yellow, and 31-40- Red). Then I need to draw a rectangular matrix which contains X x Y boxes and each box has the corresponding value from the input matrix and is also colored according to which group (i.e red, yellow,
2012 Apr 29
0
need help with avg.surv (Direct Adjusted Survival Curve)
...ot;stage.fac", var.values=c(1,2,3,4), data=larynx) Error in `contrasts<-`(`*tmp*`, value = contrasts.arg[[nn]]) :    contrasts apply only to factors" If try using var.values = c ("1","2","3","4") option, I get the following error: "Error in xmat %*% cfit$coef : non-conformable arguments In addition: Warning message: In model.matrix.default(Terms, mf, contrasts = contrast.arg) :   variable 'stage.fac' converted to a factor" Please advise me on what I am doing wrong! Regards, Manish Dalwani University of Colorado library(surv...
2013 Jan 03
5
splitting matrices
Dear useRs, i want to split a matrix having 1116rows and 12 columns. i want to split that matrix into 36 small matrices each having 12 columns and 31 rows. The big matrix should be splitted row wise. which means that the first small matrix should copy values which are in first 31 rows and 12 columns of the big matrix. similarly 2nd small matrix should contain values from 32nd to 63rd row of the