[prev in list] [next in list] [prev in thread] [next in thread]
List: r-help
Subject: [R] Extracting coefficients values with bootstrap
From: baconbeach <baconbeach () gmail ! com>
Date: 2012-04-30 20:58:29
Message-ID: 1335819509002-4599356.post () n4 ! nabble ! com
[Download RAW message or body]
Hello fellow R users,
I am trying to extract the coefficient values during a bootstrap operation.
Here is the list of my variables that I would like to extract the
coefficient values from:
(Intercept)
LogRds_25k
GeoRockbimodal volcanic rocks
GeoRockgranodiorite, quartz diorite
GeoRockintermediate volcanic rocks
GeoRockmafic intrusive rocks-diorite, gabbro
GeoRockmafic volcanic rocks
GeoRocknonmarine sedimentary rocks
GeoRockoffshelf miogeoclinal rocks
GeoRocksedimentary and mafic volcanic rocks
GeoRockundivided sedimentary rocks
GeoRockundivided volcanic rocks
There is basically 1 variable (LogRds_25k) and 1 categorical variable
(GeoRock) with 10 categories.
Here is my script:
N = length (data_As[,1])
B = 10000
stor.r2 = rep(0,B)
stor.inter = rep(0,B)
stor.Rds = rep(0,B)
stor.Bimod = rep(0,B)
stor.grano = rep(0,B)
stor.mafic_intru = rep(0,B)
stor.mafic_vol = rep(0,B)
stor.nonmarine = rep(0,B)
stor.iffshelf = rep(0,B)
stor.sedi = rep(0,B)
stor.vol = rep(0,B)
for (i in 1:B){
idx = sample(1:N, replace=T)
newdata = data_As[idx,]
LogRds <- log(newdata$Rds_25k+1)
GeoRock <- factor(newdata$GeoRock)
data_As.boot = lm(newdata$Log_Level ~
LogRds + GeoRock )
stor.r2[i] = summary(data_As.boot)$r.squared
stor.inter[i] = summary(data_As.boot)$coefficients[1,1]
stor.Rds[i] = summary(data_As.boot)$coefficients[2,1]
stor.Bimod [i] = summary(data_As.boot)$coefficients[3,1]
stor.grano[i] = summary(data_As.boot)$coefficients[4,1]
stor.inter[i] = summary(data_As.boot)$coefficients[5,1]
stor.mafic_vol [i] = summary(data_As.boot)$coefficients[6,1]
stor.nonmarine[i] = summary(data_As.boot)$coefficients[7,1]
stor.iffshelf[i] = summary(data_As.boot)$coefficients[8,1]
stor.sedi[i] = summary(data_As.boot)$coefficients[9,1]
stor.vol[i] = summary(data_As.boot)$coefficients[10,1]
}
My problem is during the bootstrap operation with replacements, some samples
do not include all the categorical variables. The way my script is written,
I get an error message because I don't specify the coefficient names.
I don't know how to arrange my script, so it knows how to deal with missing
variables.
Can somebody help me with this issue?
Thank you very much
Steeve
--
View this message in context: \
http://r.789695.n4.nabble.com/Extracting-coefficients-values-with-bootstrap-tp4599356.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic