[R-sig-Geo] earth Package question for running a loop

Nick Matzke matzke at berkeley.edu
Tue Feb 21 03:44:39 CET 2012


Haven't used earth/MARS in a month or two, but I don't 
remember this being a big issue.  Wouldn't...

names(vars)

...do it for you?

Cheers!
Nick

On 2/20/12 6:26 PM, Ona Strikas wrote:
> I don't know if anyone on the list uses the package earth to run a MARS
> analysis, but I am trying to run a loop of MARS runs and table the
> variables that it selects as explanatory. However, looking at the help file
> and names for an earth model, I can't find a good way of obtaining the
> variable names that it selects. Here are my present attempts:
>
> #attempt 1
> vars = character()
>> set.seed(3042)
>> for(j in 1:1000){
> + rows = sample(1:length(rd4km$OBJECTID), 2000, replace=FALSE)
> + subrd4km = rd4km[rows, ]
> + model = earth(ff2006 ~
> roadlength+Atl.dist+Atl.dir+roadd+easting+northing,  degree=1,
> +   data=subrd4km,  glm=list(family=poisson))
> + vars=c(vars, rownames(model$glm.coefficients))
> +
> + }
>
>> head(table(vars))
> vars
>            (Intercept)              Atl.dirN             Atl.dirNE
>                   1000                    99                   629
>              Atl.dirNW              Atl.dirS             Atl.dirSE
>                    571                   882                    55
>              Atl.dirSW              Atl.dirW  h(-0.574228-easting)
>                     79                   188                     3
>    h(-100.574-easting)   h(-104.574-easting)   h(-108.574-easting)
>                      1                     1                     5
>    h(-112.574-easting)   h(-116.574-easting)   h(-12.5742-easting)
>
> # attempt 2
> dirf = character()
> set.seed(3042)
> for(j in 1:1000){
> rows = sample(1:length(rd5$X), 2000, replace=FALSE)
> subrd5 = rd5[rows, ]
> model = earth(ff ~ roadd + Atldir,  degree=1,
>    data=subrd5,  glm=list(family="poisson"))
> dirf = c(dirf,
> dimnames(model$coefficients)[[1]][length(dimnames(model$coefficients)[[1]])])
> }
> table(dirf)
>
> The data is lightning flash density with a list of possible covariates.
>
> Thanks for any help,
> Sincerely,
> Ona Strikas
> Florida State University
> Department of Geography
> Graduate Student
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
====================================================
Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: 
http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: matzke at berkeley.edu

Mailing address:
Department of Integrative Biology
1005 Valley Life Sciences Building #3140
Berkeley, CA 94720-3140

-----------------------------------------------------
"[W]hen people thought the earth was flat, they were wrong. 
When people thought the earth was spherical, they were 
wrong. But if you think that thinking the earth is spherical 
is just as wrong as thinking the earth is flat, then your 
view is wronger than both of them put together."

Isaac Asimov (1989). "The Relativity of Wrong." The 
Skeptical Inquirer, 14(1), 35-44. Fall 1989.
http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm



More information about the R-sig-Geo mailing list