Comments (6)
Hi!
Thank you for the detailed report.
- 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.
- 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.
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.
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.
Hi @gdemin,
Thank you for quick and informative response.
-
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 theround
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. -
Looking forward to hearing more news from you soon on this.
from expss.
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.
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)
- How to not include subtotals in percent calculation? HOT 4
- Redundant column when using subtotal in columns HOT 4
- Help with val_lab() and var_lab() HOT 3
- Intermittent error: "duplicated values in labels" HOT 5
- Converting etable to huxtable leaves duplicate cells empty HOT 2
- 'do_repeat' functionality HOT 1
- Random error 'set_val_lab' - duplicated values in labels: HOT 13
- Please keep do_repeat HOT 2
- Unable to install without 'knitr' - move to Depends? HOT 1
- Problem at writting labelled csv files with accents in labels HOT 10
- Question about computing percentages with different bases HOT 3
- What happened to vlookup? HOT 1
- Where deprecated in future HOT 2
- Question about net HOT 2
- Shiny and expss HOT 2
- var_lab in net HOT 2
- Multiple response in function() HOT 4
- expss--where did it go? HOT 1
- use of `base::mtfrm` entails R 4.2 or later HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expss.