Re: [R] Creating a year-month indicator and groupby with category
Hello, First of all, I'll repost the data at end because the OP posted with a pointer ref: problems = and this must be removed for the dput output to run. Suggestion: coerce to class "data.frame" and post the output of dput(as.data.frame(dat)) Now the plot. Here are two plots of share by date, grouped by company. One with base R graphics and the other one with package ggplot2. Create a date/time column to be used by both plots. dat$date <- with(dat, ISOdate(year, month, 1)) 1) Base R plot. ylim <- range(dat$share) + c(0, 2) # make room for the legend on top comp <- unique(dat$company) # draw each line in a loop on companies # open a blank plot witth all the data, # setting the ylim as explained above plot(share ~ date, dat, type = "n", ylim = ylim) for(i in seq_along(comp)) { lines(share ~ date, subset(dat, company == comp[i]), col = i) } legend("top", legend = comp, col = seq_along(comp), lty = "solid", horiz = TRUE) 2) ggplot2 plot. library(ggplot2) ggplot(dat, aes(date, share, color = company)) + geom_line() + scale_x_datetime(date_labels = "%Y-%m") + scale_color_manual(values = c(ABC = "black", FGH = "red")) + theme_bw() 3) The data, reposted with the new pipe operator introduced in R 4.1.0 to make it look modern and slightly edited. dat |> as.data.frame() |> dput() dat <- structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), date = structure(c(1543665600, 1546344000, 1549022400, 1551441600, 155412, 1556712000, 1559390400, 1561982400, 1483272000, 1485950400, 1488369600, 1491048000, 149364, 1496318400, 1498910400, 1501588800, 1504267200, 1506859200, 1509537600, 1512129600, 1514808000, 1517486400, 1519905600, 1522584000, 1525176000, 1527854400, 1530446400, 1533124800, 1535803200, 1538395200, 1541073600, 1543665600, 1546344000, 1549022400, 1551441600, 155412, 1556712000 ), class = c("POSIXct", "POSIXt"), tzone = "GMT")), row.names = c(NA, -37L), class = "data.frame") Hope this helps, Rui Barradas Às 00:04 de 03/10/2022, Tariq Khasiri escreveu: Hello, I have the following data. I want to show in a line plot how each different company is earning over the timeline of my data sample. I'm not sure how I can create the *year-month indicator* to plot it nicely in my horizontal axis out of my dataset. After creating the *year-month* indicator ( which will be in my x axis) I want to create a dataframe where I can groupby companies over the year-month indicator by putting *share *in the y axis as variables. ### data is like the following dput(dat) structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, -37L), spec = structure(list(cols = list(year = structure(list(), class = c("collector_double", "collector")), month = structure(list(), class = c("collector_double", "collector")), company = structure(list(), class = c("collector_character", "collector")), share = structure(list(), class = c("collector_double", "collector")), com_name = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = , class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
[R] [External Help] Multivariate Polynomials in R
Dear R Users, I have written some R code for multivariate polynomials in R. I am looking forward for some help in redesigning and improving the code. Although this code was not planned initially to be released as a package, the functionality has become quite versatile over time. I will provide some examples below. If anyone is interested in multivariate polynomials and has some spare time, or has some students interested to learn some interesting math, feel free to contact me. The immediate focus should be on: 1) Writing/improving the automatic tests; 2) Redesigning the code (and build an R package); As the code has grown in size, I am very cautious to change anything, until proper tests are written. I have started to write some test code (the link to the GitHub page is below), but I am not yet very confident how to properly write the tests and also lack the time as well. I will appreciate any expertise and help on this topic. Ultimately, I hope to be able to focus more on the math topics. I will post a separate call for some of these topics. CODE DETAILS The source files are on GitHub: https://github.com/discoleo/R/blob/master/Math/Polynomials.Helper.R - (all) files named Polynomials.Helper.XXX.R are needed; (~ 25 files, including the test files); - if requested, I can also upload a zip file with all these source files; - the code started as some helper scripts (which is why all those files are mixed with other files); The multivariate polynomials are stored as data.frames and R's aggregate() function is the workhorse: but it proved sufficiently fast and the code works well even with polynomials with > 10,000 monomials. I have some older Java code which used a TreeMap (sorted map), but I do not maintain that code anymore. I was very reserved initially regarding the efficiency of the data frame; but it worked well! And it proved very useful for sub-setting specific monomials! I have attached some concrete examples below. Sincerely, Leonard ### Examples source("Polynomials.Helper.R") # - requires also the other Helper scripts; # - not strictly needed (but are loaded automatically): # library(polynom) # library(pracma) ### Example 1: n = 2; # Power "n" will be evaluated automatically p1 = toPoly.pm("x^n*y + b*z - R") p2 = toPoly.pm("y^n*z + b*x - R") p3 = toPoly.pm("z^n*x + b*y - R") pR = solve.lpm(p1, p2, p3, xn=c("z", "y")) str(pR) # 124 monomials # tweaking manually can improve the results; pR = solve.lpm(p1, p2, p3, xn=c("y", "z")) str(pR) # pR[[2]]$Rez: 19 monomials: much better; pR2 = div.pm(pR[[2]]$Rez, "x^3 + b*x - R", "x") # Divisible! str(pR2) # Order 12 polynomial in x (24 monomials); ### Note: # - the P[12] contains the distinct roots: # it is the minimal order polynomial; # - the trivial solution (x^3 + b*x = R) was removed; # - this is the naive way to solve this system (but good as Demo); # print the coefficients of x; # (will be used inside the function coeff.S3Ht below) pR2 = pR2$Rez; pR2$coeff = - pR2$coeff; # positive leading coeff; toCoeff(pR2, "x") ### Quick Check solve.S3Ht = function(R, b) { coeff = coeff.S3Ht(R, b); x = roots(coeff); # library(pracma) # Note: pracma uses leading to free coeff; z = b*x^11 - R*x^10 - 2*R^2*b*x^5 + 2*R^2*b^2*x^3 + R*b^4*x^2 - R*b^5; z = z / (- R^2*x^6 - R*b^2*x^5 + 3*R*b^3*x^3 - b^6); y = (R - z^2*x) / b; sol = cbind(x, y, z); return(sol); } coeff.S3Ht = function(R, b) { coeff = c(b^2, - 2*R*b, R^2 - b^3, 3*R*b^2, - 3*R^2*b + b^4, R^3 - 4*R*b^3, 2*R^2*b^2 - b^5, 5*R*b^4, R^4 - R^2*b^3 + b^6, - 3*R^3*b^2 - 3*R*b^5, - R^4*b + 3*R^2*b^4 - b^7, 2*R^3*b^3 - R*b^6, - R^2*b^5 + b^8); return(coeff); } R = 5; b = -2; sol = solve.S3Ht(R, b) # all 12 sets of solutions: x = sol[,1]; y = sol[,2]; z = sol[,3]; ### Test: x^2*y + b*z y^2*z + b*x z^2*x + b*y id = 1; eval.pm(p1, list(x=x[id], y=y[id], z=z[id], b=b, R=R)) ## ### Example 2: n = 5 p1 = toPoly.pm("(x + a)^n + (y + a)^n - R1") p2 = toPoly.pm("(x + b)*(y + b) - R2") # Very Naive way to solve: pR = solve.pm(p1, p2, "y") str(pR) table(pR$Rez$x) # Order 10 with 109 monomials; # [very naive!] __ 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] Help with steam graph
I think you are being dishonest. That code does not appear on hrbrmstr's vignette at least in a form that I recognize. When I run your code from the first posting with all the instances of `com_num` replaced by `com_name` and removing the `pointer` entry in dat which throws an error when trying to define dat, I get Error in `group_by()`: ! Must group by variables found in `.data`. ✖ Column `com_name` is not found. So I "rewind the process to the point where the error is reported and find dat %>%+ select(year, month, company, share, com_name) %>% + tidyr::gather(company, share, -year) # A tibble: 148 × 3 year company share1 2018 month 12 2 2019 month 1 3 2019 month 2 4 2019 month 3 5 2019 month 4 6 2019 month 5 7 2019 month 6 8 2019 month 7 9 2017 month 1 10 2017 month 2 # … with 138 more rows # ℹ Use `print(n = ...)` to see more rows So the "gathering" process seems to have removed the `com_name` column. Can exit R without saving your workspace and then construct a series of R commands that will create a reproducible example? -- David. On 10/2/22 10:03, Tariq Khasiri wrote: Actually in my main data the column name is com_num ( where mistakenly I pasted the sample data here under the com_name ). So, when I run the command successfully this is the error shows up - ▆ 1. ├─... %>% sg_legend(show = TRUE, label = "Share: ") 2. ├─streamgraph::sg_legend(., show = TRUE, label = "Share: ") 3. ├─streamgraph::sg_fill_brewer(., "PuOr") 4. ├─streamgraph::sg_axis_x(., 0.8) 5. ├─streamgraph::streamgraph(., "com_num", "n", "year") 6. │ └─base::data.frame(data) 7. ├─dplyr::ungroup(.) 8. ├─dplyr::tally(., wt = share) 9. ├─dplyr::group_by(., year, com_num) 10. └─dplyr:::group_by.data.frame(., year, com_num) 11. └─dplyr::group_by_prepare(.data, ..., .add = .add, caller_env = caller_env()) 12. └─rlang::abort(bullets, call = error_call) Any suggestions on how I can fix it ?? On Sun, 2 Oct 2022 at 09:12, David Winsemius wrote: I don’t see a column with the name ‘com_num’, so the error message makes complete sense. — David Sent from my iPhone > On Oct 2, 2022, at 5:06 AM, Tariq Khasiri wrote: > > Hi, i'm trying to create a steamgraph with the following data by creating a > unit indicator by combing the year and month. But, I'm getting error as : > > Error in `group_by()`: > ! Must group by variables found in `.data`. > ✖ Column `com_num` is not found. > Run `rlang::last_error()` to see where the error occurred. > > ### Packages needed for the code > devtools::install_github("hrbrmstr/streamgraph") > > library(tidyverse) > library(ggplot2) > library(dplyr) > library(steamgraph) > > ### Code ( The following code can be found on creator's account > https://hrbrmstr.github.io/streamgraph/ ) > > dat %>% > select(year, month, company, share, com_num) %>% > tidyr::gather(company, share, -year) %>% > group_by(year, com_num) %>% > tally(wt=share) %>% > ungroup %>% > streamgraph("com_num", "n", "year") %>% > sg_axis_x(0.8) %>% > sg_fill_brewer("PuOr") %>% > sg_legend(show=TRUE, label="Share: ") > > > ### data is like the following > > dput(dat) > structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, > 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, > 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, > 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, > 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, > 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", > "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" > ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, > 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > -37L), spec = structure(list(cols = list(year = structure(list(), class = > c("collector_double", > "collector")), month = structure(list(), class = c("collector_double", > "collector")), company = structure(list(), class = c("collector_character", > "collector")), share = structure(list(), class = c("collector_double", > "collector")), com_name = structure(list(), class = c("collector_double", > "collector"))), default = structure(list(), class = c("collector_guess", > "collector")), delim = ","), class = "col_spec"), problems = 0x7fd732028680>,
[R] Creating a year-month indicator and groupby with category
Hello, I have the following data. I want to show in a line plot how each different company is earning over the timeline of my data sample. I'm not sure how I can create the *year-month indicator* to plot it nicely in my horizontal axis out of my dataset. After creating the *year-month* indicator ( which will be in my x axis) I want to create a dataframe where I can groupby companies over the year-month indicator by putting *share *in the y axis as variables. ### data is like the following dput(dat) structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, -37L), spec = structure(list(cols = list(year = structure(list(), class = c("collector_double", "collector")), month = structure(list(), class = c("collector_double", "collector")), company = structure(list(), class = c("collector_character", "collector")), share = structure(list(), class = c("collector_double", "collector")), com_name = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = , class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")) [[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] Robust standard error
Most computer code will take a pile of numbers and return a pile of numbers. Reading the documentation should help you figure out where each measure is appropriate. It all depends on the purpose of a specific method and its assumptions and how those relate to your data, application, and model assumptions. It is important to know that information because it could change if you change your model or find other questions to ask of your data. There is no universal right answer. Tim -Original Message- From: R-help On Behalf Of Enrico Schumann Sent: Sunday, October 2, 2022 12:00 PM To: Simone Mascia Cc: r-help@r-project.org Subject: Re: [R] Robust standard error [External Email] On Sun, 02 Oct 2022, Bert Gunter writes: > On Sun, Oct 2, 2022 at 6:42 AM Simone Mascia > > wrote: > >> Is there a way to estimate Robust standard errors when using a nls() >> function? I'm trying to fit some data to a complicated model and >> everything works fine with nls() but I also wanted to obtain a robust >> estimate of my errors. >> >> I tried "coeftest(m, vcov=sandwich)" and it seems to work, but so >> does "coeftest(m, vcov = NeweyWest(m, lag = 4))" or "coeftest(m, vcov >> = kernHAC(m, kernel = "Bartlett", bw = 5, prewhite = FALSE, adjust = >> FALSE))". They return different error estimates so I wanted you to >> help me understand what I should do, if I'm doing something wrong and other >> stuff. >> >> Thank you >> > > You may get a helpful response here, but generally speaking, this list > is about R **programming**, and statistical issues/tutorials are off topic. > You might try > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstac > koverflow.com%2Fquestions%2Ftagged%2Fstatisticsdata=05%7C01%7Cteb > ert%40ufl.edu%7C86352d688e094b941f6108daa48f2bb0%7C0d4da0f84a314d76ace > 60a62331e1b84%7C0%7C0%7C638003232071609206%7CUnknown%7CTWFpbGZsb3d8eyJ > WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000 > %7C%7C%7Csdata=yFTdmRZyRqZd9F3XNsg12IvYlnWE2P6TTkRvNL6U4ZI%3D > ;reserved=0 > if you don't get adequate help here. > > -- Bert > Additionally, there is also https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2FR-sig-Robustdata=05%7C01%7Ctebert%40ufl.edu%7C86352d688e094b941f6108daa48f2bb0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638003232071609206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=WJY8zHOxsMLUv1uiHJ91q04mGVvkPi0Kg%2BYydMZMKhs%3Dreserved=0 . -- Enrico Schumann Lucerne, Switzerland https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fenricoschumann.net%2Fdata=05%7C01%7Ctebert%40ufl.edu%7C86352d688e094b941f6108daa48f2bb0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638003232071609206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=nntdbtWzMra1ZsSrTR2ZEuDNndB6J5GJ%2B1WSC%2Bhweqo%3Dreserved=0 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C86352d688e094b941f6108daa48f2bb0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638003232071609206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=6J1gU7dtTJexvDxujaA10nKYYxypFk1CMjN8qc8NQZM%3Dreserved=0 PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C86352d688e094b941f6108daa48f2bb0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638003232071609206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=qd99tAhjS4vz7SemhzyXKvpSDG%2FZD%2FtQ4BYbCtt%2Fsu8%3Dreserved=0 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.
Re: [R] Help with steam graph
Actually in my main data the column name is com_num ( where mistakenly I pasted the sample data here under the com_name ). So, when I run the command successfully this is the error shows up - ▆ 1. ├─... %>% sg_legend(show = TRUE, label = "Share: ") 2. ├─streamgraph::sg_legend(., show = TRUE, label = "Share: ") 3. ├─streamgraph::sg_fill_brewer(., "PuOr") 4. ├─streamgraph::sg_axis_x(., 0.8) 5. ├─streamgraph::streamgraph(., "com_num", "n", "year") 6. │ └─base::data.frame(data) 7. ├─dplyr::ungroup(.) 8. ├─dplyr::tally(., wt = share) 9. ├─dplyr::group_by(., year, com_num) 10. └─dplyr:::group_by.data.frame(., year, com_num) 11. └─dplyr::group_by_prepare(.data, ..., .add = .add, caller_env = caller_env()) 12. └─rlang::abort(bullets, call = error_call) Any suggestions on how I can fix it ?? On Sun, 2 Oct 2022 at 09:12, David Winsemius wrote: > I don’t see a column with the name ‘com_num’, so the error message makes > complete sense. > > — > David > > Sent from my iPhone > > > On Oct 2, 2022, at 5:06 AM, Tariq Khasiri > wrote: > > > > Hi, i'm trying to create a steamgraph with the following data by > creating a > > unit indicator by combing the year and month. But, I'm getting error as : > > > > Error in `group_by()`: > > ! Must group by variables found in `.data`. > > ✖ Column `com_num` is not found. > > Run `rlang::last_error()` to see where the error occurred. > > > > ### Packages needed for the code > > devtools::install_github("hrbrmstr/streamgraph") > > > > library(tidyverse) > > library(ggplot2) > > library(dplyr) > > library(steamgraph) > > > > ### Code ( The following code can be found on creator's account > > https://hrbrmstr.github.io/streamgraph/ ) > > > > dat %>% > > select(year, month, company, share, com_num) %>% > > tidyr::gather(company, share, -year) %>% > > group_by(year, com_num) %>% > > tally(wt=share) %>% > > ungroup %>% > > streamgraph("com_num", "n", "year") %>% > > sg_axis_x(0.8) %>% > > sg_fill_brewer("PuOr") %>% > > sg_legend(show=TRUE, label="Share: ") > > > > > > ### data is like the following > > > > dput(dat) > > structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, > > 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, > > 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, > > 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, > > 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, > > 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", > > "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" > > ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, > > 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, > > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > > -37L), spec = structure(list(cols = list(year = structure(list(), class = > > c("collector_double", > > "collector")), month = structure(list(), class = c("collector_double", > > "collector")), company = structure(list(), class = > c("collector_character", > > "collector")), share = structure(list(), class = c("collector_double", > > "collector")), com_name = structure(list(), class = c("collector_double", > > "collector"))), default = structure(list(), class = c("collector_guess", > > "collector")), delim = ","), class = "col_spec"), problems = > 0x7fd732028680>, class = c("spec_tbl_df", > > "tbl_df", "tbl", "data.frame")) > > > >[[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] Robust standard error
On Sun, 02 Oct 2022, Bert Gunter writes: > On Sun, Oct 2, 2022 at 6:42 AM Simone Mascia > wrote: > >> Is there a way to estimate Robust standard errors when using a nls() >> function? I'm trying to fit some data to a complicated model and everything >> works fine with nls() but I also wanted to obtain a robust estimate of my >> errors. >> >> I tried "coeftest(m, vcov=sandwich)" and it seems to work, but so does >> "coeftest(m, vcov = NeweyWest(m, lag = 4))" or "coeftest(m, vcov = >> kernHAC(m, kernel = "Bartlett", bw = 5, prewhite = FALSE, adjust = >> FALSE))". They return different error estimates so I wanted you to help me >> understand what I should do, if I'm doing something wrong and other stuff. >> >> Thank you >> > > You may get a helpful response here, but generally speaking, this list is > about R **programming**, and statistical issues/tutorials are off topic. > You might try > https://stackoverflow.com/questions/tagged/statistics > if you don't get adequate help here. > > -- Bert > Additionally, there is also https://stat.ethz.ch/mailman/listinfo/R-sig-Robust . -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net __ 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] Robust standard error
You may get a helpful response here, but generally speaking, this list is about R **programming**, and statistical issues/tutorials are off topic. You might try https://stackoverflow.com/questions/tagged/statistics if you don't get adequate help here. -- Bert On Sun, Oct 2, 2022 at 6:42 AM Simone Mascia wrote: > Is there a way to estimate Robust standard errors when using a nls() > function? I'm trying to fit some data to a complicated model and everything > works fine with nls() but I also wanted to obtain a robust estimate of my > errors. > > I tried "coeftest(m, vcov=sandwich)" and it seems to work, but so does > "coeftest(m, vcov = NeweyWest(m, lag = 4))" or "coeftest(m, vcov = > kernHAC(m, kernel = "Bartlett", bw = 5, prewhite = FALSE, adjust = > FALSE))". They return different error estimates so I wanted you to help me > understand what I should do, if I'm doing something wrong and other stuff. > > Thank you > > [[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] Help with steam graph
I don’t see a column with the name ‘com_num’, so the error message makes complete sense. — David Sent from my iPhone > On Oct 2, 2022, at 5:06 AM, Tariq Khasiri wrote: > > Hi, i'm trying to create a steamgraph with the following data by creating a > unit indicator by combing the year and month. But, I'm getting error as : > > Error in `group_by()`: > ! Must group by variables found in `.data`. > ✖ Column `com_num` is not found. > Run `rlang::last_error()` to see where the error occurred. > > ### Packages needed for the code > devtools::install_github("hrbrmstr/streamgraph") > > library(tidyverse) > library(ggplot2) > library(dplyr) > library(steamgraph) > > ### Code ( The following code can be found on creator's account > https://hrbrmstr.github.io/streamgraph/ ) > > dat %>% > select(year, month, company, share, com_num) %>% > tidyr::gather(company, share, -year) %>% > group_by(year, com_num) %>% > tally(wt=share) %>% > ungroup %>% > streamgraph("com_num", "n", "year") %>% > sg_axis_x(0.8) %>% > sg_fill_brewer("PuOr") %>% > sg_legend(show=TRUE, label="Share: ") > > > ### data is like the following > > dput(dat) > structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, > 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, > 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, > 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, > 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, > 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", > "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" > ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, > 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > -37L), spec = structure(list(cols = list(year = structure(list(), class = > c("collector_double", > "collector")), month = structure(list(), class = c("collector_double", > "collector")), company = structure(list(), class = c("collector_character", > "collector")), share = structure(list(), class = c("collector_double", > "collector")), com_name = structure(list(), class = c("collector_double", > "collector"))), default = structure(list(), class = c("collector_guess", > "collector")), delim = ","), class = "col_spec"), problems = 0x7fd732028680>, class = c("spec_tbl_df", > "tbl_df", "tbl", "data.frame")) > >[[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] Robust standard error
Is there a way to estimate Robust standard errors when using a nls() function? I'm trying to fit some data to a complicated model and everything works fine with nls() but I also wanted to obtain a robust estimate of my errors. I tried "coeftest(m, vcov=sandwich)" and it seems to work, but so does "coeftest(m, vcov = NeweyWest(m, lag = 4))" or "coeftest(m, vcov = kernHAC(m, kernel = "Bartlett", bw = 5, prewhite = FALSE, adjust = FALSE))". They return different error estimates so I wanted you to help me understand what I should do, if I'm doing something wrong and other stuff. Thank you [[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 with steam graph
Hi, i'm trying to create a steamgraph with the following data by creating a unit indicator by combing the year and month. But, I'm getting error as : Error in `group_by()`: ! Must group by variables found in `.data`. ✖ Column `com_num` is not found. Run `rlang::last_error()` to see where the error occurred. ### Packages needed for the code devtools::install_github("hrbrmstr/streamgraph") library(tidyverse) library(ggplot2) library(dplyr) library(steamgraph) ### Code ( The following code can be found on creator's account https://hrbrmstr.github.io/streamgraph/ ) dat %>% select(year, month, company, share, com_num) %>% tidyr::gather(company, share, -year) %>% group_by(year, com_num) %>% tally(wt=share) %>% ungroup %>% streamgraph("com_num", "n", "year") %>% sg_axis_x(0.8) %>% sg_fill_brewer("PuOr") %>% sg_legend(show=TRUE, label="Share: ") ### data is like the following dput(dat) structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, -37L), spec = structure(list(cols = list(year = structure(list(), class = c("collector_double", "collector")), month = structure(list(), class = c("collector_double", "collector")), company = structure(list(), class = c("collector_character", "collector")), share = structure(list(), class = c("collector_double", "collector")), com_name = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = , class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")) [[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.