Skip to contents

Percentage frequencies of weights

Description

The function fn_freqw is a methodological function to calculate the percentage frequencies of weights by model adjusted using the robust regression approach.

The function calculates the relative frequency distribution using the function fn_freq from Morefi package.

For fn_freq, the breaks object must be defined. For this work, a sequence of breakpoints of equal distance is used. To incorporate the number of non-weighted values \((w_{i}=1)\), a class interval 1 is added to the sequence.

A table with frequencies by class interval is returned.

The function requires defining:

  • df: A vector of data values.
  • breaks: A vector with class intervals.
  • right: Logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.

Seealso: cut() and table() functions from the R base package. : fn_freq from Morefi package

fn_freqw

The function is included in the Morefi package Morphological Relationships Fitted by Robust Regression.

The function is detailed below.

fn_freqw <- function(df, breaks, right=FALSE){
                    freq <- fn_freq(df, breaks, right=FALSE)
                    nw <- length(which(df ==1))
                    freq <- c(freq, nw)
                    freq <-  100*freq/length(df)
                    }

Examples

In the “df” object, 30 random values between 0.1 and 0.9 are generated and five values equal to 1 are added. The breaks object is a sequence of equal distances, to incorporate the number of non-weighted values (wi=1), a class interval “1” is added to the sequence.

df <- c(runif(n=30, min=0, max=1),rep(1,5))
breaks  <-  c(seq(0.1,0.9, by=0.1),1)

freq <- fn_freqw(df, breaks, right=FALSE)
freq

[0.1,0.2) [0.2,0.3) [0.3,0.4) [0.4,0.5) [0.5,0.6) [0.6,0.7) [0.7,0.8) [0.8,0.9) 11.428571 5.714286 5.714286 11.428571 2.857143 11.428571 11.428571 5.714286 [0.9,1)
5.714286 14.285714

References

Yau C (2024, deck 25). Frequency Distribution of Quantitative Data. R Tutorial An R Introduction to Statistics. https://www.r-tutor.com/elementary-statistics/quantitative-data/frequency-distribution-quantitative-data