[R] Statistical / data mining methods in R and not in SAS?
Hi, and sorry for asking such an unspecific question. Does anybody know of statistical / data mining methods that are available in R that are not in SAS ? With SAS I mean the SAS System Version 9.4 and SAS Enterprise Miner. I don't expect a complete list, just two or three examples or hints where and what to look for. I found some older comparisons, and the R methods mentioned there (GLMET, RF, ADABoost) are now supported by SAS (at least to some degree). And there exists a (massive) list of available models for the caret package here: https://rdrr.io/cran/caret/man/models.html, but it's hard to analyze the complete list. (I'm trying to answer a question of a colleague). Thanks, Friedrich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] Calculating the focal mean of a raster using an annulus
Hello esteemed R experts, I am attempting the use the 'focal' function in the raster package to calculate the mean of an annulus (as opposed to a focal mean of a circle or square). >From what I can tell, this requires me to generate a weights matrix and use >this matrix in the focal function. The problem, however, is that there are edge effects because the weights to not get readjusted along the boundary/edge of my raster. Therefore, the focal mean of the annulus near the boundary of my rasters are lower than would be expected. Code is below that repeats the problem. Please help if you can. Thank you, Sean Parks ## ## library(raster) the.raster <- raster(matrix(round(rep(seq(1,5, 0.0001), 250)), nrow=250, ncol=250)) # # Create annulus weights matrix # There is actually an error in the weights matrix that I will figure out later # Bonus points if you can identify and fix it # This error does not affect the overall issue that I am attempting to address # Please don't [publicly] make fun of me for this clunky code # w <- focalWeight(the.raster, d=0.025, type='circle') w.rev <- w for (i in 1:ncol(w)) { col <- w[,i] num.recs <- length(which(w != 0)) first.rec <- match(1/num.recs, col) last.rec <- length(col) - (first.rec- 1) non.recs <- seq(1:length(col)) non.recs <- non.recs[-c(first.rec, last.rec)] col[non.recs] <- 0 w.rev[,i] <- col } count <- length(which(w.rev != 0)) w.rev[w.rev != 0] <- 1/count ### # End of creating weights matrix ### # Now make and view the annulus raster # Note the edge effects in the top and bottom of the plot annulus.raster <- round(focal(the.raster, w=w.rev, na.rm=T, pad=T)) plot(annulus.raster) # END # # This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
[R] pixel based percentile among rasters
Hi, Say I have 1000 rasters, or a raster stack composed of 1000 rasters. I am interested in knowing the percentile for each pixel among these 1000 rasters. The result would be 1000 rasters, each depicting the percentile value of each pixel among the 1000 original rasters. Can anyone please offer suggestions on how to accomplish this task? Thanks for your help, Sean This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
[R] using correlation compound correlation structure with nlme; how to incorporate multple random effects?
Hello, I have developed this model to test change in PTFines6 over time. I have random effects of watershed (HUC3) and management type (mgmt3), and then I have the YrC/SiteID random effect which is the longitudinal time effect. But I recently found out that I need to incorporate a compound correlation structure. I found examples of this where there is just one random effect, but not my case where I have multiple. I am not sure if I just include YrC|SiteID or the entire random effect. I have tried both, and get error messages: Original code: model5.15_e=lme(PTFines6~HUC3 + YrC*mgmt3 + Bf* mgmt3 + LnGrad * mgmt3+ Precip ,random=list( ~1|HUC3,~1|mgmt3,1~(YrC)|SiteID),na.action=na.omit, data=habitat2,method="REML",control=control1) #22835 no precip interaction I have tried: model5.15_e=lme(PTFines6~HUC3 + YrC*mgmt3 + Bf* mgmt3 + LnGrad * mgmt3+ Precip ,random=list( ~1|HUC3,~1|mgmt3,1~(YrC)|SiteID),na.action=na.omit, data=habitat2, correlation=corCompSymm(form=1~(YrC)|SiteID),method="REML",control=control1) #22835 no precip interaction I get the message: incompatible formulas for groups in "random" and "correlation" I have tried: model5.15_e=lme(PTFines6~HUC3 + YrC*mgmt3 + Bf* mgmt3 + LnGrad * mgmt3+ Precip ,random=list( ~1|HUC3,~1|mgmt3,1~(YrC)|SiteID),na.action=na.omit, data=habitat2, correlation=corCompSymm(form=~1|HUC3,~1|mgmt3,1~(YrC)|SiteID),method="REML",control=control1) #22835 no precip interaction I get the error message "non-numeric argument to mathematical function Thanks for any help. Christy Meredith This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
[R] randomly select another observation with same grouping factor and year value, do for every record in dataframe
Hello, I am trying to create a function that will move through each record of a data frame, find the value in the "HUC" column, then randomly select another observation from the dataframe with the same value in "HUC" column, as well as the same value in "Yr" column as the first observation. I want the function to produce a list of the RchID of the first observation, the RchID of the second randomly chosen observation, and several other characteristics of the randomly chosen observation. Below is the code I have written, but it doesn't work. Thanks for any help. Christy test roads=read.csv("streamland23.csv") for (i in 1:nrow (roads)){ Sitetype= roads$Sitetype yr=roads$REACH_Yr initRchid=roads$RchID huc1=roads$HUC sample.df <- function(df, n) df[sample(nrow(df), n), , drop = FALSE] selected=sample.df(roads[roads$HUC == "huc1"& roads$REACH_Yr =="yr" , ], 1) output=cbind (initRchid,selected$RchID,selected$Sitetype,selected$REACH_Yr) } Christy Meredith USDA Forest Service Rocky Mountain Research Station PIBO Monitoring Data Analyst Voice: 435-755-3573 Fax: 435-755-3563 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
[R] help with for loop: new column giving count of observation for each SITEID
Hello, I think this is easy, but I can't seem to find a good way to do this in the R help. I have a list of sites, with multiple years of data for each site id. I want to create a new column that gives a number describing whether it is the 1st year ("1" ) the data was collected for the site, the second year ("2"), etc. I have different years for each siteid, but I don't care which year it was collected, just the order that it is in for that siteid. This is what I have so far, but it doesn't do the analysis separately for each SiteID. indexi<-indexg[order(indexg$SiteID,indexg$Yr),] obs=0 indexi=na.omit(indexi) for(i in 1:length(indexi$SiteID)){ obs=obs+1 indexi$obs[i]=obs } Thanks for any help you can give. Christy Meredith USDA Forest Service Rocky Mountain Research Station PIBO Monitoring Data Analyst Voice: 435-755-3573 Fax: 435-755-3563 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
Re: [R] help with for loop: new column giving count of observation for each SITEID
Not quite, I need it like this, a new number for each ordered year in the sequence within each site, regardless of what the years are, and to retain the RchID column. RchID siteyearindex 1 A 20021 2 A 20042 3 A 20053 4 B 20031 5 B 20062 6 B 20083 7 C 20021 8 C 20032 9 C 20043 Thanks so much for you help! -Original Message- From: William Dunlap [mailto:wdun...@tibco.com] Sent: Tuesday, October 30, 2012 1:07 PM To: Meredith, Christy S -FS; r-help@R-project.org Subject: RE: [R] help with for loop: new column giving count of observation for each SITEID Is this what you want? > withinGroupIndex <- function(group, ...) ave(integer(length(group)), group, ..., FUN=seq_along) > site <- c("A","A","C","D","C","A","B") > data.frame(site, index=withinGroupIndex(site)) site index 1A 1 2A 2 3C 1 4D 1 5C 2 6A 3 7B 1 You can add more arguments if the groups depend on more than one value: > year <- rep(c(1985, 2012), c(4,3)) > data.frame(site, year, index=withinGroupIndex(site, year)) site year index 1A 1985 1 2A 1985 2 3C 1985 1 4D 1985 1 5C 2012 1 6A 2012 1 7B 2012 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Meredith, Christy S > -FS > Sent: Tuesday, October 30, 2012 11:17 AM > To: r-help@R-project.org > Subject: [R] help with for loop: new column giving count of > observation for each SITEID > > > Hello, > I think this is easy, but I can't seem to find a good way to do this > in the R help. I have a list of sites, with multiple years of data for > each site id. I want to create a new column that gives a number > describing whether it is the 1st year ("1" ) the data was collected > for the site, the second year ("2"), etc. I have different years for > each siteid, but I don't care which year it was collected, just the order > that it is in for that siteid. This is what I have so far, but it doesn't do > the analysis separately for each SiteID. > > indexi<-indexg[order(indexg$SiteID,indexg$Yr),] > > obs=0 > indexi=na.omit(indexi) > for(i in 1:length(indexi$SiteID)){ > obs=obs+1 > indexi$obs[i]=obs > } > > > Thanks for any help you can give. > > Christy Meredith > USDA Forest Service > Rocky Mountain Research Station > PIBO Monitoring > Data Analyst > Voice: 435-755-3573 > Fax: 435-755-3563 > > > > > > This electronic message contains information generated by the USDA > solely for the intended recipients. Any unauthorized interception of > this message or the use or disclosure of the information it contains > may violate the law and subject the violator to civil or criminal > penalties. If you believe you have received this message in error, please > notify the sender and delete the email immediately. > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] help with for loop: new column giving count of observation for each SITEID
Thanks to you all for your help with this code Basically, the purpose of this was to create a column detailing whether it is the 1st, 2nd, 3rd, etc time that the site was sampled. I need this for creating a graph which shows this new variable on the x axis versus a variable of interest. The variable of interest can change but refers to aspects of fish habitat. Indexg$newindex refers to this new variable (perhaps not the best names, but they are indices of habitat quality and time). Ultimately, I want to create a ggplot graph with the new value on the x axis and the variable of interest in the y axis (code also shown below). I have been able to make the graph, but not all of my series are showing on the graph (only the first 5). I am not sure why this is the case. So now I have another question. Do any of you know why all the series are not showing on my graph and how to fix this? Thanks Christy #Code for new column nth time sampled indexg=read.csv("indexg.csv") indexg=data.frame(indexg) indexi<-indexg[order(indexg$SiteID,indexg$Yr),] res<-do.call(rbind,lapply(split(indexi,indexi$SiteID),function(x) data.frame(x,newindex=1:nrow(x rownames(res)<-1:nrow(res) res res$SiteID=as.factor(res$SiteID) q=ggplot(data=res,aes(x=newindex,y=Bf,group=SiteID,shape=SiteID))+geom_line() + geom_point(size=5,colour="black") Data: SiteID Yr Bf newindex 11015 2001 3.771 21015 2006 4.942 31015 2011 5.203 41035 2003 5.841 51035 2008 6.182 61039 2003 4.411 71039 2008 5.242 81047 2001 NA1 91047 2003 4.762 10 1047 2004 4.103 11 1047 2006 5.854 12 1047 2008 4.875 13 1047 2009 5.596 14 1047 2010 4.697 15 1047 2011 4.948 16 1088 2003 3.751 17 1088 2008 5.862 18 1104 2004 7.321 19 1104 2009 7.212 20 1106 2001 6.921 21 1106 2002 4.252 22 1106 2003 4.753 23 1106 2004 6.674 24 1106 2005 4.505 25 1106 2006 6.626 26 1106 2008 6.327 27 1106 2009 6.308 28 1106 2010 6.659 29 1106 2011 5.51 10 30 1110 2004 6.871 31 1110 2009 5.532 32 2702 2009 1.801 33 2944 2010 4.361 34 2946 2010 2.251 -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Tuesday, October 30, 2012 1:57 PM To: Meredith, Christy S -FS Cc: R help; William Dunlap Subject: Re: [R] help with for loop: new column giving count of observation for each SITEID HI, You can also use this:res<-do.call(rbind,lapply(split(d,d$site),function(x) data.frame(x,newindex=1:nrow(x rownames(res)<-1:nrow(res) res # RchID site year index newindex #1 1 A 2002 1 1 #2 2 A 2004 2 2 #3 3 A 2005 3 3 #4 4 B 2003 1 1 #5 5 B 2006 2 2 #6 6 B 2008 3 3 #7 7 C 2002 1 1 #8 8 C 2003 2 2 #9 9 C 2004 3 3 A.K. - Original Message - From: William Dunlap To: "Meredith, Christy S -FS" Cc: "r-help@r-project.org" Sent: Tuesday, October 30, 2012 3:43 PM Subject: Re: [R] help with for loop: new column giving count of observation for each SITEID Your data was, in R-readable format (from dput()) d <- data.frame( RchID = 1:9, site = factor(c("A", "A", "A", "B", "B", "B", "C", "C", "C"), levels = c("A", "B", "C")), year = c(2002L, 2004L, 2005L, 2003L, 2006L, 2008L, 2002L, 2003L, 2004L), index = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L)) and I am assuming that 'index' is the desired result. You can use withinGroupIndex to make a new column identical to 'index'. There are a variety of ways to add that column to an existing data.frame, one of which is within(): > within(d, newIndex <- withinGroupIndex(site)) RchID site year index newIndex 1 1 A 2002 1 1 2 2 A 2004 2 2 3 3 A 2005 3 3 4 4 B 2003 1 1 5 5 B 2006 2 2 6 6 B 2008 3 3 7 7 C 2002 1 1 8 8 C 2003 2 2 9 9 C 2004 3 3 Or is 'index' not the desired result? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: Meredith, Christy S -FS [mailto:csmered...@fs.fed.us] > Sent: Tuesday, October 30, 2012 12:20 PM > To: William Dunlap > Subject: RE: [R] help with for loop: new column giving count of > observation for each SITEID > > Not quite, > I need it like th
[R] Remove wireframe outer box but keep ticks
I would like to eliminate the outer box around a lattice wireframe graph, but the usual recommended solution, which is to assign a color of 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' command is used, as shown in the following example: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) = c("x", "y", "z") require(lattice) wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(axis.line = list(col = "transparent")), ) Is there a way to eliminate the box but keep the ticks? Seth W. Bigelow, Ph.D. Research Ecologist USDA-FS Pacific Southwest Research Station Ph: (802)-379-3444 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[alternative HTML version deleted]] __ 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.
Re: [R] Remove wireframe outer box but keep ticks
ilai/keren: Thanks for your response. It's not the 3d bounding box that I wish to eliminate, but the box that surrounds the whole figure and is drawn automatically (I call this the outer box, in contrast to the inner, 3d bounding box). The ticks attached to the bounding box are connected, in the software, to the outer box. I'm assembling a number of these graphs on one page, and the outer box makes the whole figure look clunky. Lattice is an incredible piece of software! but these small details can be difficult to nail down. --Seth -Original Message- From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai Sent: Friday, March 23, 2012 11:10 AM To: Bigelow, Seth W -FS Cc: r-help@r-project.org Subject: Re: [R] Remove wireframe outer box but keep ticks See 'box.3d' in trellis.par.get() : wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=NA))) Note you can have some finer control: wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) ) Hope this helps On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS wrote: > I would like to eliminate the outer box around a lattice wireframe > graph, but the usual recommended solution, which is to assign a color of > 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' > command is used, as shown in the following example: > > test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + > test[,2] test = cbind(test, z) > names(test) = c("x", "y", "z") > require(lattice) > wireframe(z ~ x*y, data = test, > scales=list(arrows=F), > par.settings = list(axis.line = list(col = "transparent")), > ) > > Is there a way to eliminate the box but keep the ticks? > > > Seth W. Bigelow, Ph.D. > Research Ecologist > USDA-FS Pacific Southwest Research Station > Ph: (802)-379-3444 > > > > > > This electronic message contains information generated by the USDA solely for > the intended recipients. Any unauthorized interception of this message or the > use or disclosure of the information it contains may violate the law and > subject the violator to civil or criminal penalties. If you believe you have > received this message in error, please notify the sender and delete the email > immediately. > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] Remove wireframe outer box but keep ticks
Wow, that worked liked a charm. I will include the entire working example of how to remove the outer box without losing the ticks: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) = c("x", "y", "z") require(lattice) wireframe(z ~ x*y, data = test, scales=list(arrows=F,col=1), par.settings = list(axis.line = list(col = "transparent")), ) Many thanks!!! --Seth This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. __ 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.