Wednesday, 15 January 2014

plotting in for loop with R using package eHOF -



plotting in for loop with R using package eHOF -

i want run number (~100) of ehof models using r bundle ehof, produce graphs bundle can create of models, , save jpeg files of each one. trying utilize loop accomplish quickly, not able create graphs. don't see in r studio plots window, , produce jpeg files have nil in them (as aside problem, not producing names jpeg files correctly in loop).

to produce these plots, outside loop there no problem, if illustration phone call model modsp<-hof(sp, ...) using plot(modsp) produces desired graph. within loop, nil produced, , several error messages of sort:

1: in xy.coords(x, y, xlabel, ylabel, log) : nas introduced coercion 2: in plot.window(...) : "boxp" not graphical parameter 3: in plot.window(...) : "las.h" not graphical parameter 4: in plot.window(...) : "onlybest" not graphical parameter 5: in plot.window(...) : "para" not graphical parameter

background: using r version 3.1.0 (2014-04-10) in r studio, , bundle ehof in windows 7.

my code follows:

species<- read.csv("f:/thesis_projects/chapter4_climatechange/hof/259species.csv") species<-as.data.frame(species) enviro<-read.csv("f:/thesis_projects/chapter4_climatechange/hof/environmentaldata.csv") enviro<-as.data.frame(enviro) species_enviro<-merge(enviro, species, all.x=false) hof_sp<-species_enviro[,23:25] gdd<-species_enviro[,19] library(ehof) speciescodes<-c("acpe","acru2","acsp2") modx<-null (spp in seq_along(speciescodes)){ modx[[spp]]<-hof(hof_sp[[spp]],gdd, m=1,family=binomial, bootstrap=2, freq.limit = 100) jpeg(filename = (paste(("gdd_responsecurve_",speciescodes[[spp]],".jpg"),sep="")), width =8.3, height = 8.3, units = "cm", pointsize = 8, bg="white", res = 800) print(plot((paste(c(modx[[spp]]))), boxp = true, las.h = 1, onlybest = true, para = true, gam.se = false, newdata = null, lwd=1, leg = true, add=false, xlabel="growing grade days", ylab="probability")) dev.off() }

my info looks this:

> head(gdd) [1] 996.1681 996.1681 962.0662 962.0662 945.7007 945.7007

(there lots of 1's in species info too, not in first few rows).

> head(hof_sp) acmi2 acpa acpe 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0

any advice @ appreciated! think issue plot function in loop beingness mistaken generic plot function of r. if didn't provide plenty information, happy edit question.

there several things going on here:

your speciescodes vector has codes different column names in hof_sp. seq_along(...) returns index of each element in it's argument, not element itself. the plot method hof invoked when object of class hof passed plot(...). passing paste(c(hof)) incomprehensible... your illustration not reproducible because not run info provided (did seek run it??). specifically, sample of hof_sp degenerate because there no non-zero values.

it's impossible me test code because of (4) above, seek this:

speciescodes <- c("acpe","acru2","acsp2") (spp in speciescodes) { model <- hof(hof_sp[[spp]],gdd, m=1,family=binomial, bootstrap=2, freq.limit = 100) jpeg(filename = (paste(("gdd_responsecurve_",spp,".jpg"),sep="")), width =8.3, height = 8.3, units = "cm", pointsize = 8, bg="white", res = 800) plot(model, boxp = true, las.h = 1, onlybest = true, para = true, gam.se = false, newdata = null, lwd=1, leg = true, add=false, xlabel="growing grade days", ylab="probability") dev.off() }

note invokes vector version of hof(...), gather want.

this not solve problem in (1) above (species codes not match columns names), other should work.

r for-loop plot

No comments:

Post a Comment