Dear all,
I am a new user in r and I am facing some problems with the quantile regression
specification. I have two matrix (mresultb and mresultx) with nrow=1000 and
ncol=nsim, where I specify (let's say) nsim=10. Hence, the columns in my
matrix represents each simulation of a determined variable. I need to regress
each column of mresultb on mresultx. My codes are the following:
set.seed(180185)
nsim <- 10
mresultx <- matrix(-99, nrow=1000, ncol=nsim)
mresultb <- matrix(-99, nrow=1000, ncol=nsim)
for (i in 1:nsim){
# make a matrix with 5 cols of N random uniform values
N <- 200
I <- 5
u <- replicate( 5, runif(N, 0, 1) )
# fit matrix u in another matrix of 1 column
mu <- matrix(u, nrow=1000, ncol=1)
# make auction-specific covariate
x <- runif(N, 0, 1)
mx <- matrix(rep(x,5), nrow=1000, ncol=1)
b0 <- matrix(rep(c(1),1000), nrow=1000, ncol=1)
#function for private cost
c <- b0+b0*mx+mu
#bidding strategy
b <- mx+((I+1)/I)+((I-1)/I)*mu
mresultb[,i] <- b
mresultx[,i] <- mx
qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)
M <- coef(qf05)
}
But I just can see the quantile regression coefficients for 1 simulation, not
for each i.
Maybe this is a stupid question, but i am not so familiar with this software
yet.
Thanks in advance!
Julia
[[alternative HTML version deleted]]
The problem is that I can see a matrix with the coefficients, but not with the
coefficients of all the simulations.
look at the codes now:
set.seed(180185)
nsim <- 10
mresultx <- matrix(-99, nrow=1000, ncol=nsim)
mresultb <- matrix(-99, nrow=1000, ncol=nsim)
for (i in 1:nsim){
# make a matrix with 5 cols of N random uniform values
N <- 200
I <- 5
u <- replicate( 5, runif(N, 0, 1) )
# fit matrix u in another matrix of 1 column
mu <- matrix(u, nrow=1000, ncol=1)
# make auction-specific covariate
x <- runif(N, 0, 1)
mx <- matrix(rep(x,5), nrow=1000, ncol=1)
b0 <- matrix(rep(c(1),1000), nrow=1000, ncol=1)
#function for private cost
c <- b0+b0*mx+mu
#bidding strategy
b <- mx+((I+1)/I)+((I-1)/I)*mu
mresultb[,i] <- b
mresultx[,i] <- mx
qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)
M <- matrix(-99, nrow=2, ncol=nsim)
M[,i] <- coef(qf05)
}
I am quite sure there is a mistake in the code:
qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)
because it is just generating the coefficients for one simulation, not for 10
simulations.
best,
Julia
Date: Thu, 7 Oct 2010 18:51:40 +0800
Subject: Re: [R] quantile regression
From: minhuangr@gmail.com
To: julia.lira@hotmail.co.uk
You should define M as a vector or matrix depending on the length of coef(qf05)
and let M[i] or M[,i] be coef(qf05).
On Thu, Oct 7, 2010 at 6:40 PM, Julia Lira <julia.lira@hotmail.co.uk>
wrote:
Dear all,
I am a new user in r and I am facing some problems with the quantile regression
specification. I have two matrix (mresultb and mresultx) with nrow=1000 and
ncol=nsim, where I specify (let's say) nsim=10. Hence, the columns in my
matrix represents each simulation of a determined variable. I need to regress
each column of mresultb on mresultx. My codes are the following:
set.seed(180185)
nsim <- 10
mresultx <- matrix(-99, nrow=1000, ncol=nsim)
mresultb <- matrix(-99, nrow=1000, ncol=nsim)
for (i in 1:nsim){
# make a matrix with 5 cols of N random uniform values
N <- 200
I <- 5
u <- replicate( 5, runif(N, 0, 1) )
# fit matrix u in another matrix of 1 column
mu <- matrix(u, nrow=1000, ncol=1)
# make auction-specific covariate
x <- runif(N, 0, 1)
mx <- matrix(rep(x,5), nrow=1000, ncol=1)
b0 <- matrix(rep(c(1),1000), nrow=1000, ncol=1)
#function for private cost
c <- b0+b0*mx+mu
#bidding strategy
b <- mx+((I+1)/I)+((I-1)/I)*mu
mresultb[,i] <- b
mresultx[,i] <- mx
qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)
M <- coef(qf05)
}
But I just can see the quantile regression coefficients for 1 simulation, not
for each i.
Maybe this is a stupid question, but i am not so familiar with this software
yet.
Thanks in advance!
Julia
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
On Oct 7, 2010, at 6:40 AM, Julia Lira wrote:> > Dear all, > > > > I am a new user in r and I am facing some problems with the quantile > regression specification. I have two matrix (mresultb and mresultx) > with nrow=1000 and ncol=nsim, where I specify (let's say) nsim=10. > Hence, the columns in my matrix represents each simulation of a > determined variable. I need to regress each column of mresultb on > mresultx. My codes are the following: > > > > set.seed(180185) > nsim <- 10 > mresultx <- matrix(-99, nrow=1000, ncol=nsim) > mresultb <- matrix(-99, nrow=1000, ncol=nsim)#Keep constants that do not vary .... outside the loop.> N <- 200 > I <- 5#Create an object to hold results. M <- matrix(0, ncol=2, nrow=nsim)> for (i in 1:nsim){ > # make a matrix with 5 cols of N random uniform values > > u <- replicate( 5, runif(N, 0, 1) ) > # fit matrix u in another matrix of 1 column > mu <- matrix(u, nrow=1000, ncol=1) > # make auction-specific covariate > x <- runif(N, 0, 1) > mx <- matrix(rep(x,5), nrow=1000, ncol=1) > b0 <- matrix(rep(c(1),1000), nrow=1000, ncol=1) > #function for private cost > c <- b0+b0*mx+mu > #bidding strategy > b <- mx+((I+1)/I)+((I-1)/I)*mu > mresultb[,i] <- b > mresultx[,i] <- mx > qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)# Use a a method of storing result that does not overwrite prior values> M[i, ] <- coef(qf05) > }> M [,1] [,2] [1,] 1.546023 1.060197 [2,] 1.593085 1.012752 [3,] 1.561060 1.039669 [4,] 1.555189 1.080506 [5,] 1.595738 1.030818 [6,] 1.599211 1.004429 [7,] 1.572492 1.066966 [8,] 1.619282 0.964974 [9,] 1.595431 1.028448 [10,] 1.585927 1.023855 Not sure why you created mresultb and mresultx to accept multiple columns, sinc ewhat your really wanted was the results of the regression, but if there were a reasons then they are still there to be examined.> > > But I just can see the quantile regression coefficients for 1 > simulation, not for each i. > > Maybe this is a stupid question, but i am not so familiar with this > software yet. > > > > Thanks in advance! > > > > Julia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
Hi,
Your code is of the form
for (i in 1:nsim) {
## Do something that generates variable qf05
M <- coeff(qf05)
}
This means that you are overwriting the variable M at each iteration and
so when the loop has finished you only have the coefficients from the
last simulation. There are lots of ways of getting around this, the
easiest would probably be to do something like
M <- matrix(0,nsim,2)
for (i in 1:nsim) {
## Do something that generates variable qf05
M[i,] <- coeff(qf05)
}
then M would be a nsim by 2 matrix, with each row holding the
coefficients from a different simulation. You could also look at
removing the loop by vectorising the code.
Hope this helps
Martyn
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Julia Lira
Sent: 07 October 2010 11:40
To: r-help at r-project.org
Subject: [R] quantile regression
Dear all,
I am a new user in r and I am facing some problems with the quantile
regression specification. I have two matrix (mresultb and mresultx) with
nrow=1000 and ncol=nsim, where I specify (let's say) nsim=10. Hence, the
columns in my matrix represents each simulation of a determined
variable. I need to regress each column of mresultb on mresultx. My
codes are the following:
set.seed(180185)
nsim <- 10
mresultx <- matrix(-99, nrow=1000, ncol=nsim)
mresultb <- matrix(-99, nrow=1000, ncol=nsim)
for (i in 1:nsim){
# make a matrix with 5 cols of N random uniform values
N <- 200
I <- 5
u <- replicate( 5, runif(N, 0, 1) )
# fit matrix u in another matrix of 1 column
mu <- matrix(u, nrow=1000, ncol=1)
# make auction-specific covariate
x <- runif(N, 0, 1)
mx <- matrix(rep(x,5), nrow=1000, ncol=1)
b0 <- matrix(rep(c(1),1000), nrow=1000, ncol=1)
#function for private cost
c <- b0+b0*mx+mu
#bidding strategy
b <- mx+((I+1)/I)+((I-1)/I)*mu
mresultb[,i] <- b
mresultx[,i] <- mx
qf05 <- rq(formula = mresultb[,i] ~ mresultx[,i], tau=0.5)
M <- coef(qf05)
}
But I just can see the quantile regression coefficients for 1
simulation, not for each i.
Maybe this is a stupid question, but i am not so familiar with this
software yet.
Thanks in advance!
Julia
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
________________________________________________________________________
This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}}