[R] quantile regression

Martyn Byng Martyn.Byng at nag.co.uk
Thu Oct 7 13:28:09 CEST 2010


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}}



More information about the R-help mailing list