[R] MSVAR
Hello, As I'm interested to search about the monetary transmission channel in our country by MSVAR model,Could you do me favor and tell me How I can run different types of MSVAR model (such as MSIAH(2)-VAR(2)) and finding impulse response function in different regimes and also variance decomposition? Thank you very much in advance. Best Regards, Ahmad [[alternative HTML version deleted]] __ 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.
Re: [R] Remove
In this case I cannot see an advantage to using dplyr over subset, other than if dplyr is your hammer then the problem will look like a nail, or if this is one step in a larger context where dplyr is more useful. Nor do I think this is a good use for mapply (or dplyr::group_by) because the groups are handled differently... better to introduce a data-driven columnar approach than to have three separate algorithms and bind the data frames together again. Here are three ways I came up with. I sometimes use a variation of method 3 when the logical tests are rather more complicated than this and I want to characterize those tests in the final report. ### reprex DM <- read.table( text = "GR x y A 25 125 A 23 135 A 14 145 A 35 230 B 45 321 B 47 512 B 53 123 B 55 451 C 61 521 C 68 235 C 85 258 C 80 654", header = TRUE, stringsAsFactors = FALSE ) # 1 Hardcoded logic DM1 <- subset( DM , "A" == GR & 15 <= x & x <= 30 | "B" == GR & 40 <= x & x <= 50 | "C" == GR & 60 <= x & x <= 75 ) DM1 #>GR x y #> 1 A 25 125 #> 2 A 23 135 #> 5 B 45 321 #> 6 B 47 512 #> 9 C 61 521 #> 10 C 68 235 # 2 relational approach cond <- read.table( text = "GR minx maxx A 15 30 B 40 50 C 60 75 ", header = TRUE ) DM2 <- merge( DM, cond, by = "GR" ) DM2 <- subset( DM2, minx <= x & x <= maxx, select = -c( minx, maxx ) ) DM2 #>GR x y #> 1 A 25 125 #> 2 A 23 135 #> 5 B 45 321 #> 6 B 47 512 #> 9 C 61 521 #> 10 C 68 235 # 3 Construct selection vector sel <- rep( FALSE, nrow( DM ) ) for ( i in seq.int( nrow( cond ) ) ) { sel <- sel | ( cond$GR[ i ] == DM$GR & cond$minx[ i ] <= DM$x & DM$x <= cond$maxx[ i ] ) } DM3 <- DM[ sel, ] DM3 #>GR x y #> 1 A 25 125 #> 2 A 23 135 #> 5 B 45 321 #> 6 B 47 512 #> 9 C 61 521 #> 10 C 68 235 ### On Fri, 8 Dec 2017, Michael Hannon wrote: library(dplyr) DM <- read.table( text='GR x y A 25 125 A 23 135 . . . ) DM %>% filter((GR == "A" & (x >= 15) & (x <= 30)) | (GR == "B" & (x >= 40) & (x <= 50)) | (GR == "C" & (x >= 60) & (x <= 75))) On Fri, Dec 8, 2017 at 4:48 PM, Ashta wrote: Hi David, Ista and all, I have one related question Within one group I want to keep records conditionally. example within group A I want keep rows that have " x" values ranged between 15 and 30. group B I want keep rows that have " x" values ranged between 40 and 50. group C I want keep rows that have " x" values ranged between 60 and 75. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 35 230 B 45 321 B 47 512 B 53 123 B 55 451 C 61 521 C 68 235 C 85 258 C 80 654',header = TRUE, stringsAsFactors = FALSE) The end result will be A 25 125 A 23 135 B 45 321 B 47 512 C 61 521 C 68 235 Thank you On Wed, Dec 6, 2017 at 10:34 PM, David Winsemius wrote: On Dec 6, 2017, at 4:27 PM, Ashta wrote: Thank you Ista! Worked fine. Here's another (possibly more direct in its logic?): DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ] GR x y 5 B 25 321 6 B 25 512 7 B 25 123 8 B 25 451 -- David On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn wrote: Hi Ashta, There are many ways to do it. Here is one: vars <- sapply(split(DM$x, DM$GR), var) DM[DM$GR %in% names(vars[vars > 0]), ] Best Ista On Wed, Dec 6, 2017 at 6:58 PM, Ashta wrote: Thank you Jeff, subset( DM, "B" != x ), this works if I know the group only. But if I don't know that group in this case "B", how do I identify group(s) that all elements of x have the same value? On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller wrote: subset( DM, "B" != x ) This is covered in the Introduction to R document that comes with R. -- Sent from my phone. Please excuse my brevity. On December 6, 2017 3:21:12 PM PST, David Winsemius wrote: On Dec 6, 2017, at 3:15 PM, Ashta wrote: Hi all, In a data set I have group(GR) and two variables x and y. I want to remove a group that have the same record for the x variable in each row. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 12 230 B 25 321 B 25 512 B 25 123 B 25 451 C 11 521 C 14 235 C 15 258 C 10 654',header = TRUE, stringsAsFactors = FALSE) In this example the output should contain group A and C as group B has the same record for the variable x . The result will be A 25 125 A 23 135 A 14 145 A 12 230 C 11 521 C 14 235 C 15 258 C 10 654 Try: DM[ !duplicated(DM$x) , ] How do I do it R? Thank you. __ 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. David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary t
Re: [R] Remove
library(dplyr) DM <- read.table( text='GR x y A 25 125 A 23 135 . . . ) DM %>% filter((GR == "A" & (x >= 15) & (x <= 30)) | (GR == "B" & (x >= 40) & (x <= 50)) | (GR == "C" & (x >= 60) & (x <= 75))) On Fri, Dec 8, 2017 at 4:48 PM, Ashta wrote: > Hi David, Ista and all, > > I have one related question Within one group I want to keep records > conditionally. > example within > group A I want keep rows that have " x" values ranged between 15 and 30. > group B I want keep rows that have " x" values ranged between 40 and 50. > group C I want keep rows that have " x" values ranged between 60 and 75. > > > DM <- read.table( text='GR x y > A 25 125 > A 23 135 > A 14 145 > A 35 230 > B 45 321 > B 47 512 > B 53 123 > B 55 451 > C 61 521 > C 68 235 > C 85 258 > C 80 654',header = TRUE, stringsAsFactors = FALSE) > > > The end result will be > A 25 125 > A 23 135 > B 45 321 > B 47 512 > C 61 521 > C 68 235 > > Thank you > > On Wed, Dec 6, 2017 at 10:34 PM, David Winsemius > wrote: >> >>> On Dec 6, 2017, at 4:27 PM, Ashta wrote: >>> >>> Thank you Ista! Worked fine. >> >> Here's another (possibly more direct in its logic?): >> >> DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ] >> GR x y >> 5 B 25 321 >> 6 B 25 512 >> 7 B 25 123 >> 8 B 25 451 >> >> -- >> David >> >>> On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn wrote: Hi Ashta, There are many ways to do it. Here is one: vars <- sapply(split(DM$x, DM$GR), var) DM[DM$GR %in% names(vars[vars > 0]), ] Best Ista On Wed, Dec 6, 2017 at 6:58 PM, Ashta wrote: > Thank you Jeff, > > subset( DM, "B" != x ), this works if I know the group only. > But if I don't know that group in this case "B", how do I identify > group(s) that all elements of x have the same value? > > On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller > wrote: >> subset( DM, "B" != x ) >> >> This is covered in the Introduction to R document that comes with R. >> -- >> Sent from my phone. Please excuse my brevity. >> >> On December 6, 2017 3:21:12 PM PST, David Winsemius >> wrote: >>> On Dec 6, 2017, at 3:15 PM, Ashta wrote: Hi all, In a data set I have group(GR) and two variables x and y. I want to remove a group that have the same record for the x variable in each row. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 12 230 B 25 321 B 25 512 B 25 123 B 25 451 C 11 521 C 14 235 C 15 258 C 10 654',header = TRUE, stringsAsFactors = FALSE) In this example the output should contain group A and C as group B has the same record for the variable x . The result will be A 25 125 A 23 135 A 14 145 A 12 230 C 11 521 C 14 235 C 15 258 C 10 654 >>> >>> Try: >>> >>> DM[ !duplicated(DM$x) , ] How do I do it R? Thank you. __ 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. >>> >>> David Winsemius >>> Alameda, CA, USA >>> >>> 'Any technology distinguishable from magic is insufficiently advanced.' >>> -Gehm's Corollary to Clarke's Third Law >>> >>> __ >>> 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-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-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. >> >> David Winsemius >> Alameda, CA, USA >> >> 'Any technology distinguishable from magic is insufficiently advanced.' >> -Gehm's Corollary to Clarke's Third Law >> >> >> >> >> > > __
Re: [R] Remove
> On Dec 8, 2017, at 4:48 PM, Ashta wrote: > > Hi David, Ista and all, > > I have one related question Within one group I want to keep records > conditionally. > example within > group A I want keep rows that have " x" values ranged between 15 and 30. > group B I want keep rows that have " x" values ranged between 40 and 50. > group C I want keep rows that have " x" values ranged between 60 and 75. When you have a problem where there are multiple "parallel: parameters, the function to "reach for" is `mapply`. mapply( your_selection_func, group_vec, min_vec, max_vec) ... and this will probably return the values as a list (of dataframes if you build the function correctly, so you may may need to then do: do.call(rbind, ...) -- David. > > > DM <- read.table( text='GR x y > A 25 125 > A 23 135 > A 14 145 > A 35 230 > B 45 321 > B 47 512 > B 53 123 > B 55 451 > C 61 521 > C 68 235 > C 85 258 > C 80 654',header = TRUE, stringsAsFactors = FALSE) > > > The end result will be > A 25 125 > A 23 135 > B 45 321 > B 47 512 > C 61 521 > C 68 235 > > Thank you > > On Wed, Dec 6, 2017 at 10:34 PM, David Winsemius > wrote: >> >>> On Dec 6, 2017, at 4:27 PM, Ashta wrote: >>> >>> Thank you Ista! Worked fine. >> >> Here's another (possibly more direct in its logic?): >> >> DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ] >> GR x y >> 5 B 25 321 >> 6 B 25 512 >> 7 B 25 123 >> 8 B 25 451 >> >> -- >> David >> >>> On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn wrote: Hi Ashta, There are many ways to do it. Here is one: vars <- sapply(split(DM$x, DM$GR), var) DM[DM$GR %in% names(vars[vars > 0]), ] Best Ista On Wed, Dec 6, 2017 at 6:58 PM, Ashta wrote: > Thank you Jeff, > > subset( DM, "B" != x ), this works if I know the group only. > But if I don't know that group in this case "B", how do I identify > group(s) that all elements of x have the same value? > > On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller > wrote: >> subset( DM, "B" != x ) >> >> This is covered in the Introduction to R document that comes with R. >> -- >> Sent from my phone. Please excuse my brevity. >> >> On December 6, 2017 3:21:12 PM PST, David Winsemius >> wrote: >>> On Dec 6, 2017, at 3:15 PM, Ashta wrote: Hi all, In a data set I have group(GR) and two variables x and y. I want to remove a group that have the same record for the x variable in each row. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 12 230 B 25 321 B 25 512 B 25 123 B 25 451 C 11 521 C 14 235 C 15 258 C 10 654',header = TRUE, stringsAsFactors = FALSE) In this example the output should contain group A and C as group B has the same record for the variable x . The result will be A 25 125 A 23 135 A 14 145 A 12 230 C 11 521 C 14 235 C 15 258 C 10 654 >>> >>> Try: >>> >>> DM[ !duplicated(DM$x) , ] How do I do it R? Thank you. __ 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. >>> >>> David Winsemius >>> Alameda, CA, USA >>> >>> 'Any technology distinguishable from magic is insufficiently advanced.' >>> -Gehm's Corollary to Clarke's Third Law >>> >>> __ >>> 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-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-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. >> >> David Winsemius >> Alameda, CA, USA >>
Re: [R] Remove
Hi David, Ista and all, I have one related question Within one group I want to keep records conditionally. example within group A I want keep rows that have " x" values ranged between 15 and 30. group B I want keep rows that have " x" values ranged between 40 and 50. group C I want keep rows that have " x" values ranged between 60 and 75. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 35 230 B 45 321 B 47 512 B 53 123 B 55 451 C 61 521 C 68 235 C 85 258 C 80 654',header = TRUE, stringsAsFactors = FALSE) The end result will be A 25 125 A 23 135 B 45 321 B 47 512 C 61 521 C 68 235 Thank you On Wed, Dec 6, 2017 at 10:34 PM, David Winsemius wrote: > >> On Dec 6, 2017, at 4:27 PM, Ashta wrote: >> >> Thank you Ista! Worked fine. > > Here's another (possibly more direct in its logic?): > > DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ] > GR x y > 5 B 25 321 > 6 B 25 512 > 7 B 25 123 > 8 B 25 451 > > -- > David > >> On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn wrote: >>> Hi Ashta, >>> >>> There are many ways to do it. Here is one: >>> >>> vars <- sapply(split(DM$x, DM$GR), var) >>> DM[DM$GR %in% names(vars[vars > 0]), ] >>> >>> Best >>> Ista >>> >>> On Wed, Dec 6, 2017 at 6:58 PM, Ashta wrote: Thank you Jeff, subset( DM, "B" != x ), this works if I know the group only. But if I don't know that group in this case "B", how do I identify group(s) that all elements of x have the same value? On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller wrote: > subset( DM, "B" != x ) > > This is covered in the Introduction to R document that comes with R. > -- > Sent from my phone. Please excuse my brevity. > > On December 6, 2017 3:21:12 PM PST, David Winsemius > wrote: >> >>> On Dec 6, 2017, at 3:15 PM, Ashta wrote: >>> >>> Hi all, >>> In a data set I have group(GR) and two variables x and y. I want to >>> remove a group that have the same record for the x variable in each >>> row. >>> >>> DM <- read.table( text='GR x y >>> A 25 125 >>> A 23 135 >>> A 14 145 >>> A 12 230 >>> B 25 321 >>> B 25 512 >>> B 25 123 >>> B 25 451 >>> C 11 521 >>> C 14 235 >>> C 15 258 >>> C 10 654',header = TRUE, stringsAsFactors = FALSE) >>> >>> In this example the output should contain group A and C as group B >>> has the same record for the variable x . >>> >>> The result will be >>> A 25 125 >>> A 23 135 >>> A 14 145 >>> A 12 230 >>> C 11 521 >>> C 14 235 >>> C 15 258 >>> C 10 654 >> >> Try: >> >> DM[ !duplicated(DM$x) , ] >>> >>> How do I do it R? >>> Thank you. >>> >>> __ >>> 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. >> >> David Winsemius >> Alameda, CA, USA >> >> 'Any technology distinguishable from magic is insufficiently advanced.' >> -Gehm's Corollary to Clarke's Third Law >> >> __ >> 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-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-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. > > David Winsemius > Alameda, CA, USA > > 'Any technology distinguishable from magic is insufficiently advanced.' > -Gehm's Corollary to Clarke's Third Law > > > > > __ 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.
Re: [R] lmerTest Issues
Have you read the error and installed package "purrr"? On Windows at least, previously-installed packages can get removed if you attempt to update them while you have another instance of R open at that time using said packages. Best to close all your instances of R before updating, but you can do that now to recover. -- Sent from my phone. Please excuse my brevity. On December 8, 2017 2:30:09 PM PST, Andrew Harmon wrote: >Hello all, > >Everything was working very well. Now when I try to load lmerTest >using: >library("lmerTest"), I get this error: > >Error: package or namespace load failed for ‘lmerTest’ in >loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = >vI[[j]]): > there is no package called ‘purrr’ > > >Nothing I've done has worked. I have uninstalled both R and R studio. >I've >updated packages as well, but nothing works. > >Any suggestions? > >Thanks, > >Drew > > [[alternative HTML version deleted]] > >__ >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-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] lmerTest Issues
Hello all, Everything was working very well. Now when I try to load lmerTest using: library("lmerTest"), I get this error: Error: package or namespace load failed for ‘lmerTest’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called ‘purrr’ Nothing I've done has worked. I have uninstalled both R and R studio. I've updated packages as well, but nothing works. Any suggestions? Thanks, Drew [[alternative HTML version deleted]] __ 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] Need help with labeling a plot correctly
Hi all, Eons ago (~2007) Hadley Wickham extremely generously helped me developed a means for plotting temporal activity w/ ggplot. I need to revisit this and have it working again. I failed to copy the entire legacy code over to my traveling laptop from my workstation, but found a partial bit of the code in an old 2009 Gmail attachment. I am slated to do a graduate seminar at UF G'ville and needed to discuss temporal activity. I have been working my feeble brain again and revisiting the almost complete code and have it partially working by doing step by step sections of code and carefully making sure no typos that could screw up syntax. The partial code Hadley developed for me is below and is now working more or less with R 3.4.3 (2017-11-30). What I need to do is have the missing bit of code so that the Y- Axis of the plots has time of night rather than the "elapsed seconds." As a note this is for bat activity data so data points begin after sunset on a given night and end at sunrise the following day so date/times span 2 calender days with a midnight roll-over. The code below was provided by Hadley and works except for the Y axis labeling with correct times. I can email a sample of the raw data if anyone is able to help. Cheers, Bruce ++ library(zoo) library(cluster) library(lattice) library(vegan) library(chron) library(MASS) library(ggplot2) # activity plots that Hadley Wickham helped develop back in ~2007 #New from Hadley *s*etwd("C:/Bats/Temporal data") #C:\Bats\Temporal data source("date.r") All <- read.csv("C:/Bats/Temporal data/TECTemporal.CSV") Ptepar <-subset(All, Species == "Ptepar") str(Ptepar) # Notice that date and time are factors - you need to convert them # into dates. This doesn't happen automatically in R. Also, the syntax to # make dates isn't exactly intuitive. Ptepar$Date <- as.Date(Ptepar$Date, "%m/%d/%Y") Ptepar$Time <- as.POSIXct(strptime(as.character(Ptepar$Time), "%H:%M")) Ptepar$datetime <- as.POSIXct(strptime(paste(Ptepar$Date, format(Ptepar$Time, "%H:%M")), "%Y-%m-%d %H:%M")) # For a given time, give the time the evening started # (this will be the previous day if the time is in the morning) evening <- function(date) { update(date, yday = yday(date) - ifelse(am(date), 1, 0), hour = 18, minute = 0, second = 0) } # Now we calculate the number of seconds since the start of the evening Ptepar$elapsed <- as.double(Ptepar$datetime - evening(Ptepar$datetime), "secs") ggplot(Ptepar, aes(Date, elapsed, colour = Location)) + geom_jitter() + facet_wrap(~ Species) The resulting plot appears fine however I need to have the Y axis display time of night rather than the elapsed seconds. __ 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.
Re: [R] trying to find the multiple combinations...
As Burt and Jeff stated that there is an infinite set of solutions. If you are interested in a particular solution, such as getting 15.0078, you can easily achieve that by trial and error; that is fix 1 or 2 variables and change the the rest till you get the desired solution. I tried that and came up with the same solution as you listed. if you are interested in a set of solutions within a tolerance, then that will be a different story. HTH EK On Fri, Dec 8, 2017 at 1:37 AM, Benjamin Sabatini wrote: > Hi, > > I'm trying to find a way to determine what multiples of the combination of > three or more numbers equals a forth number. > > So, if I had a number set like: > > c(13.4689, 12.85212, 17.05071) > > What combination and multiples of these numbers would average to 15.0078? > (so, something that would tell me x, y, and z in (x*13.4689 + y*12.85212+ > z*17.05071) / x+y+z) = 15.0078 > > I think this is doable with aggregate? > > [[alternative HTML version deleted]] > > __ > 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. > [[alternative HTML version deleted]] __ 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] Elastic net
Dear R users, I am using "Glmnet" package in R for applying "elastic net" method. In elastic net, two penalities are applied one is lambda1 for LASSO and lambda2 for ridge ( zou, 2005) penalty. How can I write the code to pre-chose the lambda1 for LASSO and lambda2 for ridge without using cross-validation Thanks in advance Tayo [[alternative HTML version deleted]] __ 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.
Re: [R] trying to find the multiple combinations...
Please keep all replies onlist if there is no reason to keep them private. I am not a free, private consultant (and so might choose to ignore your followups); and I don't have all or necessarily the best answers anyway. So give yourself the maximal chance to be helped by others. Anyway, ?expand.grid is what you're looking for I think as an alternative to nested loops. If "results" is a vector of calculated results, i.e. the averages for the grid of combinations you generate, and "target" is your desired target (average), here of 15.0078, then which.min(abs(results - target)) gives you the index of the closest results and abs(results - target) < tol gives you a vector of logicals of results that are within tol of the target. This is all pretty basic stuff, which suggests that you really need to spend some time with an R tutorial or two. Here are some suggestions, but a web search would uncover many more, some of which might be more suitable for you: https://www.rstudio.com/online-learning/#R This list can help (not sure if I did here), but it cannot replace such homework on your own. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Dec 8, 2017 at 9:15 AM, Benjamin Sabatini wrote: > Hi, > > Yes, actually, I could set an upper limit and grind through the > possibilities to find a minimal set or a few if that's what you mean. Close > to the result would be OK, too. Otherwise it would go on forever, I > suppose. > > At first I was thinking of just trying to write three for loops to test > for every set of the multiples of x, y, and z between something like 1 and > 10,000, but I understand that this is not at all efficient in R. So, > (1*13.4689 > + 1*12.85212+ 1*17.05071) / 1+1+1), (1*13.4689 + 2*12.85212+ 1*17.05071) > / 1+2+1)... > > Is there a better way? If I solve for z is it then easier with an upper > limit? So, z = x*0.753288 + y*1.0552 > and then loop it? > > -- > *From:* Bert Gunter > *Sent:* Friday, December 8, 2017 3:16 PM > *To:* Jeff Newmiller > *Cc:* R-help; Benjamin Sabatini > *Subject:* Re: [R] trying to find the multiple combinations... > > Are x,y, and z supposed to be positive whole numbers? If so, there may be > no solutions. If there is a solution set, of course any multiple of the set > is a solution set, so presumably you want a minimal set in some sense. This > strikes me as a hard problem mathematically, but maybe there is some > obvious way to set an upper bound on a minimal x,y, and z, in which case a > simple grid search could then be used. > > Naturally, if any real numbers are sought, Jeff is correct. > > Cheers, > Bert > > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > On Fri, Dec 8, 2017 at 12:19 AM, Jeff Newmiller > wrote: > > Solve for one of your variables and it will be given in terms of the other > two. That is, there is a whole infinite plane of solutions. No, aggregate > will not be sufficient to enumerate the solution set.. > -- > Sent from my phone. Please excuse my brevity. > > On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini < > sunsca...@hotmail.com> wrote: > >Hi, > > > >I'm trying to find a way to determine what multiples of the combination > >of three or more numbers equals a forth number. > > > >So, if I had a number set like: > > > >c(13.4689, 12.85212, 17.05071) > > > >What combination and multiples of these numbers would average to > >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + > >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > > > >I think this is doable with aggregate? > > > > [[alternative HTML version deleted]] > > This is a plain text mailing list. Please learn how to use your email > program. > > > > >__ > >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-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/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > [[alternative HTML version deleted]] __ 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.
Re: [R] Curiously short cycles in iterated permutations with the same seed
Landau's function gives the maximum cycle length of a permutation. See.,e.g., http://mathworld.wolfram.com/LandausFunction.html. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Dec 7, 2017 at 9:34 PM, Eric Berger wrote: > Hi Boris, > Do a search on "the order of elements of the symmetric group". (This search > will also turn up homework questions and solutions.) You will understand > why you are seeing this once you understand how a permutation is decomposed > into cycles and how the order relates to a partition of n (n=10 in your > case). > > Enjoy! > Eric > > > On Fri, Dec 8, 2017 at 6:39 AM, Boris Steipe > wrote: > > > I have noticed that when I iterate permutations of short vectors with the > > same seed, the cycle lengths are much shorter than I would expect by > > chance. For example: > > > > X <- 1:10 > > Xorig <- X > > start <- 112358 > > N <- 10 > > > > for (i in 1:N) { > > seed <- start + i > > for (j in 1:1000) { # Maximum cycle length to consider > > set.seed(seed)# Re-seed RNG to same initial state > > X <- sample(X)# Permute X and iterate > > if (all(X == Xorig)) { > > cat(sprintf("Seed:\t%d\tCycle: %d\n", seed, j)) > > break() > > } > > } > > } > > > > Seed: 112359 Cycle: 14 > > Seed: 112360 Cycle: 14 > > Seed: 112361 Cycle: 8 > > Seed: 112362 Cycle: 14 > > Seed: 112363 Cycle: 8 > > Seed: 112364 Cycle: 10 > > Seed: 112365 Cycle: 10 > > Seed: 112366 Cycle: 10 > > Seed: 112367 Cycle: 9 > > Seed: 112368 Cycle: 12 > > > > I understand that I am performing the same permutation operation over and > > over again - but I don't see why that would lead to such a short cycle > (in > > fact the cycle for the first 100,000 seeds is never longer than 30). Does > > this have a straightforward explanation? > > > > > > Thanks! > > Boris > > > > __ > > 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. > > > > [[alternative HTML version deleted]] > > __ > 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. > [[alternative HTML version deleted]] __ 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.
Re: [R] trying to find the multiple combinations...
Are x,y, and z supposed to be positive whole numbers? If so, there may be no solutions. If there is a solution set, of course any multiple of the set is a solution set, so presumably you want a minimal set in some sense. This strikes me as a hard problem mathematically, but maybe there is some obvious way to set an upper bound on a minimal x,y, and z, in which case a simple grid search could then be used. Naturally, if any real numbers are sought, Jeff is correct. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Dec 8, 2017 at 12:19 AM, Jeff Newmiller wrote: > Solve for one of your variables and it will be given in terms of the other > two. That is, there is a whole infinite plane of solutions. No, aggregate > will not be sufficient to enumerate the solution set.. > -- > Sent from my phone. Please excuse my brevity. > > On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini < > sunsca...@hotmail.com> wrote: > >Hi, > > > >I'm trying to find a way to determine what multiples of the combination > >of three or more numbers equals a forth number. > > > >So, if I had a number set like: > > > >c(13.4689, 12.85212, 17.05071) > > > >What combination and multiples of these numbers would average to > >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + > >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > > > >I think this is doable with aggregate? > > > > [[alternative HTML version deleted]] > > This is a plain text mailing list. Please learn how to use your email > program. > > > > >__ > >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-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. > [[alternative HTML version deleted]] __ 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.
Re: [R] trying to find the multiple combinations...
Solve for one of your variables and it will be given in terms of the other two. That is, there is a whole infinite plane of solutions. No, aggregate will not be sufficient to enumerate the solution set.. -- Sent from my phone. Please excuse my brevity. On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini wrote: >Hi, > >I'm trying to find a way to determine what multiples of the combination >of three or more numbers equals a forth number. > >So, if I had a number set like: > >c(13.4689, 12.85212, 17.05071) > >What combination and multiples of these numbers would average to >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > >I think this is doable with aggregate? > > [[alternative HTML version deleted]] This is a plain text mailing list. Please learn how to use your email program. > >__ >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-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.