Displaying 20 results from an estimated 60000 matches similar to: "avoiding loops?"
2012 Jun 16
2
How to specify "newdata" in a Cox-Modell with a time dependent interaction term?
Dear Mr. Therneau, Mr. Fox, or to whoever, who has some time...
I don't find a solution to use the "survfit" function (package:
survival) for a defined pattern of covariates with a Cox-Model
including a time dependent interaction term. Somehow the definition of
my "newdata" argument seems to be erroneous.
I already googled the problem, found many persons having the
2002 Dec 27
2
RSvgDevice & sapply(plotmeans)
Hi,
anybody know why this not works for several
plots ?
When i set onefile=T the plots are stacked one about another
, onefile=F only the first plot is shown in AllbusMeansPlots.svg.
[h2 is a data.frame]
......hist and sapply works for several plots nice with RSvgDevice !
Maybe setting the title after apply is a problem, but until yet i didn't
found a better solution ?
library(RSvgDevice)
2012 Jul 24
1
unable to run spatial lag and error models on large data
Hi:
First my apologies for cross-posting. A few days back I posted my queries ar R-sig-geo but did not get any response. Hence this post.
I am working on two parcel-level housing dataset to estimate the impact of various variables on home sale prices.
I created the spatial weight metrics in ArcGIS 10 using sale
year of four nearest houses to assign weights. Next, I ran LM tests and
then ran
2005 Jan 12
4
"model.response" error
When I installed R 2.0.1 (replacing 1.9.0) for Windows, a code using
"model.response" began acting up. Here are the first several lines of a
code I had been tweaking for a spatial model (the code is mostly that of
Roger Bivand--I am adapting it to a slightly different data structure and
the problem I'm sure is with my changes, not his code).
<command name> <- function
2008 Apr 21
1
Avoiding a loop
Dear R-users,
I've been working with three different data sets (X, Y and Z) with the same
dimension (i.e, n \times k). What I needed to do was to conform a 4th data
set, i.e. FINAL, which first row was the X's first row, its second row was
the Y's first row, and its third row was the Z's first row, and so on.
My code is below. Is it possible to avoid the loop?
Thanks in advance,
2010 Jun 04
2
Build Design Matrix with avoiding loops
Dear R users,
I'd like to build a simple design matrix in a efficient way. I naively
wrote the code below.
####
n = 15
k = 3
nbPerGrp = c(5,5,5)
xT <- list()
for (i in 1:k){
xT[[i]] <- rep(0, k)
xT[[i]][i] <- 1
}
X <- matrix(nrow = n, ncol = k) #design matrix
for (i in 1:nbPerGrp[1]){
X[i,] <- xT[[1]]
}
for (i in 1:k-1){
for (j
2010 Sep 23
1
Newey West and Singular Matrix + library(sandwich)
thank you, achim. I will try chol2inv.
sandwich is a very nice package, but let me make some short
suggestions. I am not a good econometrician, so I do not know what
prewhitening is, and the vignette did not explain it. "?coeftest" did
not work after I loaded the library. automatic bandwidth selection
can be a good thing, but is not always.
as to my own little function, I like the
2009 Apr 11
2
who happenly read these two paper Mohsen Pourahmadi (biometrika1999, 2000)
http://biomet.oxfordjournals.org/cgi/reprint/86/3/677 biometrika1999
http://biomet.oxfordjournals.org/cgi/reprint/94/4/1006 biometrika2000
Hi All:
I just want to try some luck.
I am currenly working on my project,one part of my project is to
reanalysis the kenward cattle data by using the method in Mohsen's paper,but
I found I really can get the same or close output as he did,so,any
2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
Hello my friends,
here is a code I wrote with no loops on matrix that is taking too long (2
seconds and I call him 720 times --> 12 minutes):
mat1 and mat2 are both matrix with 103 columns and 164 rows.
sequence <- matrix(seq(1 : ncol(mat1)))
returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1)
function<- function(mat1, mat2, colNb, day){
2011 Apr 18
2
Avoiding loop
Hi everyone.
I'm using matrix product such as :
#Generate some data
NCols = 5
NRows = 5
A = matrix(runif(NCols*NRows), ncol=NCols)
B = matrix(runif(NCols*NRows), ncol=NCols)
#First calculation
R = A%*%B
for(i in 1:100)
{
R = R%*%B
}
I would like to know if it was possible to avoid the loop by using something
like mapply or anything else.
Tx in advance,
Phil
--
View this message
2011 Jul 12
1
Avoiding loops to detect number of coincidences
Hi all,
I have this information on a file ht.txt, imagine it is a data frame without
labels:
1 1 1 8 1 1 6 4 1 3 1 3 3
And on other table called "pru.txt" I have sequences similar this
4 1 1 8 1 1 6 4 1 3 1 3 3
1 6 1 8 1 1 6 4 1 3 1 3 3
1 1 1 8 1 1 6 4 1 3 1 3 3
6 6 6 8 1 1 6 4 1 3 1 3 3
I want to now how many positions are identical between each row
in pru compared with ht.
n and m
2009 Dec 07
2
data.frame to "stacked frame"
Hi,
have anybody a hint how i could avoid the cumbersome way (..especially
the value part)
change the data representation from n column data.frame to an stacked
representation.
many thanks
Christian
#example data
dfw <- as.data.frame(matrix(runif(10*10),ncol=10))
dfw$group <- sample(c("X","Z"),nrow(dfw),replace=T,prob=c(0.75,0.25))
# change
var <-
2009 Mar 21
1
How to avoid switching on input type?
Hi,
I need some help improving this ugly code I wrote. I would like to shift
forward a zoo object, matrix, ts, or list by "shift" items (default 1) and
fill the holes with 0's.
The code below works, but it looks ugly. I could write a function
lag.zerofill() which calls the two functions below depending on the class()
of the item passed in, but that feels very unlike R.
What is
2002 Dec 21
1
apply vs. sapply
Hi,
sapply((1:NCOL(hermes)),function(x) hist(hermes[,x],main=names(hermes)[x]))
.......this works , but i would like use it with apply to generate many plots in one step!
####################################################################
>>apply((1:ncol(hermes)),2,function(x) hist(hermes[,x],main=names(hermes)[x]))
Error in apply(1:ncol(hermes), 2, function(x) hist(hermes[, x], main =
2011 Aug 04
2
Efficient way of creating a shifted (lagged) variable?
Hello!
I have a data set:
set.seed(123)
y<-data.frame(week=seq(as.Date("2010-01-03"), as.Date("2011-01-31"),by="week"))
y$var1<-c(1,2,3,round(rnorm(54),1))
y$var2<-c(10,20,30,round(rnorm(54),1))
# All I need is to create lagged variables for var1 and var2. I looked
around a bit and found several ways of doing it. They all seem quite
complicated - while in
2006 Mar 31
1
mutual information for two time series
Hi I hope this is going to the right place. I am trying to write a program
which uses KernSmooth library to estimate mutual information between two
time series at various different lags. At the moment it’s producing negative
values, which is supposed to be impossible (something is fishy). I am
summing across one row of the matrix to get p(value is in bin x) and summing
across the columns to get
2002 Feb 27
2
return()
Hi,
i get only one value, but expect ncol values - what's wrong ?
test <- function(){
for (i in 1:ncol(configData))
x <- subset(configData, Q71 == 1 & configData[,i] ==1 , select =
configData[,i])
y <- (dim(x)[1]/dim(configData)[1])*100
return(y) }
thanks for advance & regards,
Christian
2006 Feb 17
3
Matrix indexing in a loop
How do you specify matrix location a[i,j] (or a[i-1,j], etc.) in a "for"
loop?
I am looking for a flexible method of indexing neighbors over a series
of lags (1,2,3...) and I may wish to extend this method to 3D arrays.
Example:
Data matrix
> fun
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
For each element a[i,j] in
2013 Sep 02
1
R dataframe and looping help
HI,
You may try this:
dat1<- read.table(text="
CustID TripDate Store Bread Butter Milk Eggs
1 2-Jan-12 a 2 0 2 1
1 6-Jan-12 c 0 3 3 0
1 9-Jan-12 a 3 3 0 0
1 31-Mar-13 a 3 0 0 0
2 31-Aug-12 a 0 3 3 0
2 24-Sep-12 a 3 3 0 0
2 25-Sep-12 b 3 0 0 0
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- dat1[,-c(1:3)]
res<- lapply(seq_len(ncol(dat2)),function(i)
2005 Jan 03
2
matrix and error in points, plot ?
Hi,
Would a specialist of the "point" or "plot" functions try the following:
mat<-matrix(c(1.836767,4.025989,0.6396777,0.3764444),ncol=2)
plot(mat)
points(mat[1,],col="red")
..A lag appears on x for mat [1,1] between the two displays.
I wonder if this example may be due to a bug or to the mis-use of a matrix
in the plot() points() functions. In case of