Giter Site home page Giter Site logo

Comments (6)

gdemin avatar gdemin commented on June 23, 2024 1

Hi!
Thank you for the detailed report.

  1. expss uses built-in R round function. It's behaviour is documented:

Note that for rounding off a 5, the IEC 60559 standard (see also β€˜IEEE 754’) is expected to be used, β€˜go to the even digit’. Therefore round(0.5) is 0 and round(-1.5) is -2.

Personally, I wish it would be left as is to be consistent with other parts of R. But if you consider it is a serious issue I can change this behaviour.

  1. I will investigate it - perhaps it is a bug. However, it is rather strange that SPSS ignores 0% and 100% values. For sufficiently large bases R function which I use internally calculates significances for this edge case without any issues:
prop.test(x = c(9, 19), n = c(85, 19)) # x is number of successes, n - number of trials

#	2-sample test for equality of proportions with continuity correction
#
# data:  c(9, 19) out of c(85, 19)
# X-squared = 58.636, df = 1, p-value = 1.897e-14
# alternative hypothesis: two.sided
# 95 percent confidence interval:
#  -0.9917263 -0.7965090
# sample estimates:
#    prop 1    prop 2 
# 0.1058824 1.0000000 

from expss.

gdemin avatar gdemin commented on June 23, 2024 1

Hi @khanhhtt

I will add option about rounding in the next version. But I cant promise anything about when it will be ready.

As for workaround, you can set expss_digits(3) and then round numbers with code below:

library(expss)
round2 = function(x, digits = 0) {
    posneg = sign(x)
    z = abs(x)*10^digits
    z = z + 0.5 + sqrt(.Machine$double.eps)
    z = trunc(z)
    z = z/10^digits
    z*posneg
}

round_table_values = function(tbl, digits = 1){
    col_index = seq_along(tbl)[-1]
    cell_pattern = "^(.*?)([-0-9.]+)(.*?)$"
    for(i in col_index){
        curr = tbl[[i]]
        if(is.character(curr)){
           numeric_values = suppressWarnings(as.numeric(gsub(cell_pattern, "\\2", curr)))
           numeric_values = round2(numeric_values, digits = digits)
           not_na_index = which(!is.na(numeric_values))
           curr[not_na_index] = sapply(not_na_index, 
                                                 function(cell_index)
                                                     gsub(cell_pattern, 
                                                          paste0("\\1", numeric_values[cell_index], "\\3"), 
                                                          curr[cell_index])
                                                 )
        } else {
            curr = round2(curr, digits = digits)
        }
        tbl[[i]] = curr
        
    }
    tbl
}

data(mtcars)
expss_digits(3)
mtcars = apply_labels(mtcars,
                      mpg = "Miles/(US) gallon",
                      cyl = "Number of cylinders",
                      disp = "Displacement (cu.in.)",
                      hp = "Gross horsepower",
                      drat = "Rear axle ratio",
                      wt = "Weight (lb/1000)",
                      qsec = "1/4 mile time",
                      vs = "Engine",
                      vs = c("V-engine" = 0,
                             "Straight engine" = 1),
                      am = "Transmission",
                      am = c("Automatic" = 0,
                             "Manual"=1),
                      gear = "Number of forward gears",
                      carb = "Number of carburetors"
)

mtcars_table = cross_cpct(mtcars, 
                          list(cyl, gear),
                          list(total(), vs, am)
)

res = significance_cpct(mtcars_table)

round_table_values(res)

from expss.

gdemin avatar gdemin commented on June 23, 2024 1

Fixed in version 0.11.6
Rounding is set with expss_round_half_to_even(FALSE).
For SPSS significance there is an argument as_spss in significance_cpct and others.

from expss.

khanhhtt avatar khanhhtt commented on June 23, 2024

Hi @gdemin,

Thank you for quick and informative response.

  1. This is also a surprise for me when I get used to R that the built-in R round function has a different behaviour than what I usually practice. I know that it is great if all packages of R could be consistency, and that behaviour of the round function might be useful for people in other fields. But it's also great if there could be an option so that I can choose the behaviour of rounding that is suitable for my purpose. And I think it will ease any concerns when people use SPSS to compare the result.

  2. Looking forward to hearing more news from you soon on this.

from expss.

khanhhtt avatar khanhhtt commented on June 23, 2024

Hi @gdemin,

I hope you are doing well 😊
I just would like to know if there is any news on your side.
Do you have the plan regarding the adjustment of rounding in expss? Or if there is not, could you please help suggest some work around that could solve my concern?

Many thanks!

from expss.

khanhhtt avatar khanhhtt commented on June 23, 2024

Hi @gdemin,

That's great! Thank you so much for spending time on Christmas day to give me the workaround solution.
This is all I need for now 😊

from expss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.