Skip to content

Commit 9cf3740

Browse files
committed
add comment docs
1 parent b1baf3e commit 9cf3740

File tree

1 file changed

+130
-6
lines changed

1 file changed

+130
-6
lines changed

Library/Rlapack/stats.vb

+130-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
Imports System.Drawing
8484
Imports System.IO
8585
Imports System.Runtime.CompilerServices
86+
Imports System.Runtime.InteropServices
8687
Imports System.Text
8788
Imports Microsoft.VisualBasic.CommandLine.Reflection
8889
Imports Microsoft.VisualBasic.ComponentModel.Collection
@@ -92,13 +93,15 @@ Imports Microsoft.VisualBasic.ComponentModel.Ranges.Model
9293
Imports Microsoft.VisualBasic.Data.Bootstrapping
9394
Imports Microsoft.VisualBasic.Data.Framework.IO
9495
Imports Microsoft.VisualBasic.Data.GraphTheory
96+
Imports Microsoft.VisualBasic.Emit.Delegates
9597
Imports Microsoft.VisualBasic.Imaging
9698
Imports Microsoft.VisualBasic.Linq
9799
Imports Microsoft.VisualBasic.Math
98100
Imports Microsoft.VisualBasic.Math.Calculus
99101
Imports Microsoft.VisualBasic.Math.Distributions
100102
Imports Microsoft.VisualBasic.Math.LinearAlgebra
101103
Imports Microsoft.VisualBasic.Math.LinearAlgebra.Matrix
104+
Imports Microsoft.VisualBasic.Math.LinearAlgebra.Matrix.MDSScale
102105
Imports Microsoft.VisualBasic.Math.Matrix
103106
Imports Microsoft.VisualBasic.Math.Quantile
104107
Imports Microsoft.VisualBasic.Math.Statistics
@@ -124,12 +127,6 @@ Imports RInternal = SMRUCC.Rsharp.Runtime.Internal
124127
Imports std = System.Math
125128
Imports stdVector = Microsoft.VisualBasic.Math.LinearAlgebra.Vector
126129
Imports vec = SMRUCC.Rsharp.Runtime.Internal.Object.vector
127-
Imports Microsoft.VisualBasic.Math.LinearAlgebra.Matrix.MDSScale
128-
Imports Microsoft.VisualBasic.Emit.Delegates
129-
Imports System.Runtime.InteropServices
130-
131-
132-
133130

134131
#If NET48 Then
135132
Imports Pen = System.Drawing.Pen
@@ -2061,6 +2058,133 @@ Module stats
20612058
Return df
20622059
End Function
20632060

2061+
''' <summary>
2062+
''' **Kurtosis** is a statistical measure that describes the "tailedness" of the probability distribution of a
2063+
''' real-valued random variable. In simpler terms, it indicates the extent to which the tails of the distribution
2064+
''' differ from those of a normal distribution.
2065+
'''
2066+
''' ### Key Points about Kurtosis:
2067+
'''
2068+
''' 1. **Definition**:
2069+
'''
2070+
''' - Kurtosis is the fourth standardized moment of a distribution.
2071+
''' - It is calculated as the average of the squared deviations of the data from its mean, raised to the fourth power, standardized by the standard deviation raised to the fourth power.
2072+
'''
2073+
''' 2. **Types of Kurtosis**:
2074+
'''
2075+
''' - **Mesokurtic**: Distributions with kurtosis similar to that of the normal distribution (kurtosis value of 3). The tails of a mesokurtic distribution are neither particularly fat nor particularly thin.
2076+
''' - **Leptokurtic**: Distributions with positive kurtosis greater than 3. These distributions have "fat tails" and a sharp peak, indicating more frequent large deviations from the mean than a normal distribution.
2077+
''' - **Platykurtic**: Distributions with kurtosis less than 3. These distributions have "thin tails" and a flatter peak, indicating fewer large deviations from the mean than a normal distribution.
2078+
'''
2079+
''' 3. **Excess Kurtosis**:
2080+
'''
2081+
''' - Often, kurtosis is reported as "excess kurtosis," which is the kurtosis value minus 3. This adjustment makes the kurtosis of a normal distribution equal to 0.
2082+
''' - Positive excess kurtosis indicates a leptokurtic distribution, while negative excess kurtosis indicates a platykurtic distribution.
2083+
'''
2084+
''' 4. **Interpretation**:
2085+
'''
2086+
''' - High kurtosis in a data set is an indicator that data has heavy tails or outliers. This can affect the performance of statistical models and methods that assume normality.
2087+
''' - Low kurtosis indicates that the data has light tails and lacks outliers.
2088+
'''
2089+
''' 5. **Applications**:
2090+
'''
2091+
''' - In finance, kurtosis is used to describe the distribution of returns of an investment. A high kurtosis indicates a higher risk of extreme returns.
2092+
''' - In data analysis, kurtosis helps in understanding the shape of the data distribution and identifying potential outliers.
2093+
'''
2094+
''' 6. **Calculation in R**:
2095+
'''
2096+
''' - The `kurtosis()` function in the `e1071` package can be used to calculate kurtosis in R.
2097+
''' - Alternatively, kurtosis can be calculated manually using the formula:
2098+
'''
2099+
''' ```R
2100+
''' kurtosis &lt;- sum((data - mean(data))^4) / ((length(data) - 1) * sd(data)^4) - 3
2101+
''' ```
2102+
'''
2103+
''' kurtosis is a statistical measure for understanding the shape of a data distribution, particularly the behavior
2104+
''' of its tails. It is widely used in various fields, including finance, data analysis, and statistics.
2105+
''' </summary>
2106+
''' <param name="x"></param>
2107+
''' <returns></returns>
2108+
''' <example>
2109+
''' # Example data
2110+
''' data &lt;- c(2, 4, 4, 4, 5, 5, 7, 9);
2111+
''' # Calculate kurtosis using e1071 package
2112+
''' kurtosis_value &lt;- kurtosis(data);
2113+
''' print(kurtosis_value);
2114+
''' # Manual calculation of excess kurtosis
2115+
''' n &lt;- length(data);
2116+
''' mean_data &lt;- mean(data);
2117+
''' sd_data &lt;- sd(data);
2118+
''' kurtosis_manual &lt;- sum((data - mean_data)^4) / ((n - 1) * sd_data^4) - 3;
2119+
''' print(kurtosis_manual);
2120+
''' </example>
2121+
<ExportAPI("kurtosis")>
2122+
Public Function kurtosis(<RRawVectorArgument> x As Object) As Object
2123+
Return CLRVector.asNumeric(x).Kurtosis
2124+
End Function
2125+
2126+
''' <summary>
2127+
''' **Skewness**
2128+
'''
2129+
''' Skewness is a fundamental statistical measure used to describe the asymmetry of the probability distribution of a
2130+
''' real-valued random variable. It provides insights into the direction and extent of the deviation from a symmetric
2131+
''' distribution.
2132+
'''
2133+
''' ### Key Aspects of Skewness:
2134+
'''
2135+
''' 1. **Definition**:
2136+
'''
2137+
''' - Skewness is the third standardized moment of a distribution.
2138+
''' - It is calculated as the average of the cubed deviations of the data from its mean, standardized by the standard deviation raised to the third power.
2139+
'''
2140+
''' 2. **Types of Skewness**:
2141+
'''
2142+
''' - **Zero Skewness**: Indicates a symmetric distribution where the mean, median, and mode are all equal.
2143+
''' - **Positive Skewness (Right-Skewed)**: The tail on the right side of the distribution is longer or fatter. In this case, the mean is greater than the median.
2144+
''' - **Negative Skewness (Left-Skewed)**: The tail on the left side of the distribution is longer or fatter. Here, the mean is less than the median.
2145+
'''
2146+
''' 3. **Interpretation**:
2147+
'''
2148+
''' - Skewness values close to zero suggest a nearly symmetric distribution.
2149+
''' - Positive values indicate right-skewed distributions, while negative values indicate left-skewed distributions.
2150+
''' - The magnitude of the skewness value reflects the degree of asymmetry.
2151+
'''
2152+
''' 4. **Applications**:
2153+
'''
2154+
''' - **Finance**: Used to analyze the distribution of returns on investments, helping investors understand the potential for extreme outcomes.
2155+
''' - **Economics**: Assists in examining income distributions, enabling economists to assess income inequality.
2156+
''' - **Natural Sciences**: Describes the distribution of experimental data in scientific research.
2157+
'''
2158+
''' 5. **Considerations**:
2159+
'''
2160+
''' - Skewness is just one aspect of distribution shape and should be considered alongside other statistical measures like kurtosis for a comprehensive understanding.
2161+
''' - For small sample sizes, the estimation of skewness can be unreliable.
2162+
'''
2163+
''' In essence, skewness is a statistical tool for understanding the asymmetry of data distributions,
2164+
''' with wide-ranging applications in various fields such as finance, economics, and the natural
2165+
''' sciences.
2166+
'''
2167+
''' </summary>
2168+
''' <param name="x"></param>
2169+
''' <returns></returns>
2170+
''' <example>
2171+
''' # Example data
2172+
''' data &lt;- c(2, 4, 4, 4, 5, 5, 7, 9);
2173+
''' # Calculate skewness using e1071 package
2174+
''' skewness_value &lt;- skewness(data);
2175+
''' print(skewness_value);
2176+
''' # Manual calculation of skewness
2177+
''' n &lt;- length(data);
2178+
''' mean_data &lt;- mean(data);
2179+
''' sd_data &lt;- sd(data);
2180+
''' skewness_manual &lt;- sum((data - mean_data)^3) / ((n - 1) * sd_data^3);
2181+
''' print(skewness_manual);
2182+
''' </example>
2183+
<ExportAPI("skewness")>
2184+
Public Function skewness(<RRawVectorArgument> x As Object) As Object
2185+
Return CLRVector.asNumeric(x).Skewness
2186+
End Function
2187+
20642188
''' <summary>
20652189
''' ### Earth Mover's Distance
20662190
'''

0 commit comments

Comments
 (0)