Download the PHP package macocci7/php-frequency-table without Composer
On this page you can find all versions of the php package macocci7/php-frequency-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download macocci7/php-frequency-table
More information about macocci7/php-frequency-table
Files in macocci7/php-frequency-table
Package php-frequency-table
Short Description it's easy to use for creating frequency distribution tables.
License MIT
Informations about the package php-frequency-table
PHP-FrequencyTable
1. Features
PHP-FrequencyTable
is a library to operate Frequency Tables easily.
You can create Frequency Tables easily just by setting data in array and Class Range.
You can get or save them in some formats, Markdown Table, CSV, TSV and HTML.
English(default) and Japanese are supported.
You can also get parsed data as hash array of PHP.
2. Contents
- 1. Features
- 2. Contents
- 3. Requirements
- 4. Installation
- 5. Usage
- 5.1. Basic Usage
- 5.2. Changing Data and Class Range
- 5.3. Changing Columns for Output
- 5.4. Changing Language
- 5.5. Saving data into CSV
- 5.6. Saving data into TSV
- 5.7. Saving data into HTML
- 5.8. Saving data into Markdown
- 5.9. Retrieving Parsed Data
- 5.10. Reverse Classes
- 6. Examples
- 7. LICENSE
3. Requirements
- PHP 8.1 or later
- Composer
4. Installation
5. Usage
- 5.1. Basic Usage
- 5.2. Changing Data and Class Range
- 5.3. Changing Columns for Output
- 5.4. Changing Language
- 5.5. Saving data into CSV
- 5.6. Saving data into TSV
- 5.7. Saving data into HTML
- 5.8. Saving data into Markdown
- 5.9. Retrieving Parsed Data
5.1. Basic Usage
You can use FrequencyTable class as follows.
-
PHP: examples/BasicUsage.php
-
Output: examples/BasicUsage.md
-
View: examples/BasicUsage.md
Class Frequency RelativeFrequency ClassValue ClassValue * Frequency 0 ~ 10 2 0.40 5.0 10.0 10 ~ 20 2 0.40 15.0 30.0 20 ~ 30 1 0.20 25.0 25.0 Total 5 1.00 --- 65.0 Mean --- --- --- 13.0 -
Details:
- Import autoloader:
require_once __DIR__ . '/../vendor/autoload.php';
- Declare:
use Macocci7\PhpFrequencyTable\FrequencyTable;
- Instantiate:
new FrequencyTable()
- Option Params:
data
,classRange
,columns2Show
data
: arrayclassRange
: intcolumns2Show
: array, acceptable values are as follows- 'Class'
- 'Frequency'
- 'CumulativeFrequency'
- 'RelativeFrequency'
- 'CumulativeRelativeFrequency'
- 'ClassValue'
- 'ClassValue * Frequency'
- 'Subtotal'
- 'RelativeSubtotal'
- 'CumulativeRelativeSubtotal'
- Option Params:
- Mean Row:
meanOff()
as default, add bymeanOn()
. - Get Frequency Table: by
markdown()
in markdown format.
- Import autoloader:
5.2. Changing Data and Class Range
You can change data and class range after instantiation.
-
PHP: examples/ChangeDataClassRange.php
-
Output: examples/ChangeDataClassRange.md
-
View: examples/ChangeDataClassRange.md
Frequency Tables
Group A
Class Frequency RelativeFrequency ClassValue ClassValue * Frequency 20 ~ 40 2 0.29 30.0 60.0 40 ~ 60 1 0.14 50.0 50.0 60 ~ 80 2 0.29 70.0 140.0 80 ~ 100 2 0.29 90.0 180.0 Total 7 1.00 --- 430.0 Mean --- --- --- 61.4 Group B
Class Frequency RelativeFrequency ClassValue ClassValue * Frequency 0 ~ 25 1 0.13 12.5 12.5 25 ~ 50 1 0.13 37.5 37.5 50 ~ 75 3 0.38 62.5 187.5 75 ~ 100 2 0.25 87.5 175.0 100 ~ 125 1 0.13 112.5 112.5 Total 8 1.00 --- 525.0 Mean --- --- --- 65.6 - Details:
- Set Class Range:
setClassRange()
- Set Data:
setData()
- Set Class Range:
5.3. Changing Columns for Output
-
PHP: examples/ChangeColumns.php
-
Output: examples/ChangeColumns.md
-
View: examples/ChangeColumns.md
Changing Columns
Case1:
Class Frequency 0 ~ 10 1 10 ~ 20 2 20 ~ 30 4 30 ~ 40 2 40 ~ 50 1 Total 10 Case2:
Class Frequency RelativeFrequency 0 ~ 10 1 0.10 10 ~ 20 2 0.20 20 ~ 30 4 0.40 30 ~ 40 2 0.20 40 ~ 50 1 0.10 Total 10 1.00 Case3:
Class Frequency CumulativeFrequency RelativeFrequency CumulativeRelativeFrequency ClassValue ClassValue * Frequency Subtotal RelativeSubtotal CumulativeRelativeSubtotal 0 ~ 10 1 1 0.10 0.10 5.0 5.0 5.00 0.02 0.02 10 ~ 20 2 3 0.20 0.30 15.0 30.0 25.00 0.11 0.13 20 ~ 30 4 7 0.40 0.70 25.0 100.0 100.00 0.43 0.55 30 ~ 40 2 9 0.20 0.90 35.0 70.0 65.00 0.28 0.83 40 ~ 50 1 10 0.10 1.00 45.0 45.0 40.00 0.17 1.00 Total 10 10 1.00 1.00 --- 250.0 235.00 1.00 1.00 Mean --- --- --- --- --- 25.0 23.50 --- --- - Details:
- Get Acceptable Columns:
getValidColumns2Show()
- Get Current Columns:
getColumns2Show()
- Set Columns:
setColumns2Show()
- Get Acceptable Columns:
5.4. Changing Language
English and Japanese are supported. (English as default)
-
PHP: examples/ChangeLang.php
-
Output: examples/ChangeLang.md
-
View: examples/ChangeLang.md
Supported Languages
Language:[eng]
Class Frequency CumulativeFrequency RelativeFrequency CumulativeRelativeFrequency ClassValue ClassValue * Frequency Subtotal RelativeSubtotal CumulativeRelativeSubtotal 0 ~ 10 1 1 0.14 0.14 5.0 5.0 5.00 0.04 0.04 10 ~ 20 3 4 0.43 0.57 15.0 45.0 37.00 0.32 0.36 20 ~ 30 2 6 0.29 0.86 25.0 50.0 45.00 0.38 0.74 30 ~ 40 1 7 0.14 1.00 35.0 35.0 30.00 0.26 1.00 Total 7 7 1.00 1.00 --- 135.0 117.00 1.00 1.00 Mean --- --- --- --- --- 19.3 16.71 --- --- Language:[ja]
階級 度数 累積度数 相対度数 累積相対度数 階級値 階級値 × 度数 小計 相対小計 累積相対小計 0 ~ 10 1 1 0.14 0.14 5.0 5.0 5.00 0.04 0.04 10 ~ 20 3 4 0.43 0.57 15.0 45.0 37.00 0.32 0.36 20 ~ 30 2 6 0.29 0.86 25.0 50.0 45.00 0.38 0.74 30 ~ 40 1 7 0.14 1.00 35.0 35.0 30.00 0.26 1.00 合計 7 7 1.00 1.00 --- 135.0 117.00 1.00 1.00 平均 --- --- --- --- --- 19.3 16.71 --- --- - Details:
- Get Supported Langs:
langs()
- Get Current Lang:
lang()
- Set Lang:
- English(default):
lang('eng')
- Japanese:
lang('ja')
- English(default):
- Get Supported Langs:
5.5. Saving data into CSV
-
PHP
-
Result:
test.csv
-
Details:
-
There're 2 options for saving CSV.
save(PATH)
:PATH
must have.csv
extension.-
csv()
: params as follows$path
: File Path.- Bytes of csv file will be returned as type of int.
false
will be returned when saving fails.- When
null
is given, csv will be returned as type of string.
$quotation
: each values will be quoted with$quotation
.- double quot(default): specify
'"'
- single quot: specify
"'"
- double quot(default): specify
$eol
: The end of each line will end with$eol
."\n"
:LF
(Line Feed)"\r"
:CR
(Carrige Return)"\r\n"
:CRLF
(Carrige Return + Line Feed)
For example:
results in
-
5.6. Saving data into TSV
-
PHP
-
Result:
test.tsv
-
Details:
-
There're 2 options for saving TSV
save(PATH)
:PATH
must have.tsv
extension.-
tsv()
: params as follows$path
: File Path.- Bytes of tsv file will be returned as type of int.
false
will be returned when saving fails.- When
null
is given, tsv will be returned as type of string.
$quotation
: each values will be quoted with$quotation
.- double quot(default): specify
'"'
- single quot: specify
"'"
- double quot(default): specify
$eol
: The end of each line will end with$eol
."\n"
:LF
(Line Feed)"\r"
:CR
(Carrige Return)"\r\n"
:CRLF
(Carrige Return + Line Feed)
For example:
results in
-
5.7. Saving data into HTML
-
PHP
-
Result:
test.html
-
View:
-
with css like this:
-
html view:
-
-
Details:
-
There're 2 options for saving html:
save(PATH)
:PATH
must have.html
extension.-
html(PATH)
: param as follows$path
: File Path.- Bytes of html file will be returned as type of int.
false
will be returned when saving fails.- When
null
is given, html will be returned as type of string.
-
5.8. Saving data into Markdown
-
PHP
-
Result:
test.md
-
View:
test.md
Class Frequency RelativeFrequency ClassValue ClassValue * Frequency 0 ~ 10 2 0.40 5.0 10.0 10 ~ 20 2 0.40 15.0 30.0 20 ~ 30 1 0.20 25.0 25.0 Total 5 1.00 --- 65.0 Mean --- --- --- 13.0 -
Details:
-
There're 2 options for saving markdown
save(PATH)
:PATH
must have.md
extension.-
markdown()
: param as follows.\$path
: File Path.- Bytes of markdown file will be returned as type of int.
false
will be returned when saving fails.- When
null
is given, markdown will be returned as type of string.
-
5.9. Retrieving Parsed Data
You can also retrieve parsed data without showing Frequency Table.
Use parse()
method. parse()
method returns Hash Array as follows.
-
PHP
- Result
You can use the parsed data like this:
-
PHP
- Output
5.10. Reverse Classes
You can set the list of classes in reverse order by using reverseClasses()
method.
-
PHP:
-
Output:
-
View:
Class Frequency RelativeFrequency ClassValue ClassValue * Frequency 20 ~ 30 1 0.20 25.0 25.0 10 ~ 20 2 0.40 15.0 30.0 0 ~ 10 2 0.40 5.0 10.0 Total 5 1.00 --- 65.0
6. Examples
- Example.md
- ChangeDataClassRange.md
- ChangeColumns.md
- ChangeLang.md
- ExampleCases.md
- PopulationInJapan2022.md
- OhtaniShohei2023.md
- OutlierDetection.md
- RetrieveParsedData.txt
- ReverseClasses.md
- FrequencyTableTest.php : all usage is written in this code.
7. LICENSE
MIT
Document Written: 2023/05/18
Last Updated: 2025/01/02
Copyright (c) 2023-2025 macocci7