Wolfram言語

確率と統計における数量

数量を使って派生分布を構築する

TransformedDistributionを使って数量値関数の分布を指定する.

In[1]:=
Click for copyable input
speed = \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "speed of sound in air", Typeset`boxes$$ = TemplateBox[{ InterpretationBox[" ", 1], "\"speeds of sound in dry air at 20 \[Degree]C and 1 \ atmosphere pressure\"", "speeds of sound in dry air at 20 \[Degree]C and 1 atmosphere \ pressure", "\"SpeedOfSound\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {{ "type" -> "MultiClash", "word" -> "", "template" -> "Assuming ${word1} is referring to ${desc1}. \ Use as ${desc2} instead. Use \"${word3}\" as ${desc3}. Use \"${word4}\ \" as ${desc4}.", "count" -> "4", "Values" -> {{ "name" -> "Unit", "word" -> "the input", "desc" -> "a unit", "input" -> "*MC.%7E-_*Unit-"}, { "name" -> "Formula", "word" -> "the input", "desc" -> "a formula", "input" -> "*MC.%7E-_*Formula-"}, { "name" -> "Thermodynamic", "word" -> "air", "desc" -> "a thermodynamic material", "input" -> "*MC.%7E-_*Thermodynamic-"}, { "name" -> "Chemical", "word" -> "air", "desc" -> "a chemical compound", "input" -> "*MC.%7E-_*Chemical-"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.8160297`7.363250959003981, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{398., {30., 18.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\);
In[2]:=
Click for copyable input
distance\[ScriptCapitalD] = TransformedDistribution[speed*Quantity[t, "Seconds"], t \[Distributed] UniformDistribution[{2, 4}]]
Out[2]=

分布の単位をキロメートルに変換する.

In[3]:=
Click for copyable input
UnitConvert[distance\[ScriptCapitalD], "Kilometers"]
Out[3]=

TransformedDistributionを使って確率変数を数量と組み合せる.

In[4]:=
Click for copyable input
TransformedDistribution[ Subscript[x, 0] + v*t, {Subscript[x, 0] \[Distributed] NormalDistribution[\!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "2 m", Typeset`boxes$$ = TemplateBox[{"2", "\"m\"", "meters", "\"Meters\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {{ "type" -> "Clash", "word" -> "m", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "Unit", "desc" -> "a unit", "input" -> "*C.m-_*Unit-"}, { "name" -> "Variable", "desc" -> "a variable", "input" -> "*C.m-_*Variable-"}}}, { "type" -> "Unit", "word" -> "m", "template" -> "Assuming ${desc1} for \"${word}\". Use \ ${desc2} instead", "count" -> "3", "Values" -> {{ "name" -> "Meters", "desc" -> "meters", "input" -> "UnitClash_*m.*Meters--"}, { "name" -> "MinimsUS", "desc" -> "US minims of volume", "input" -> "UnitClash_*m.*MinimsUS--"}, { "name" -> "Minutes", "desc" -> "minutes of time", "input" -> "UnitClash_*m.*Minutes--"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 1.4079785`7.600141016624048, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{86., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\), \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "2 cm", Typeset`boxes$$ = TemplateBox[{"2", "\"cm\"", "centimeters", "\"Centimeters\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 3.2360033`7.961553949319721, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{70., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)], v \[Distributed] RayleighDistribution[\!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "5 kmph", Typeset`boxes$$ = TemplateBox[{"5", RowBox[{"\"km\"", " ", "\"/\"", " ", "\"h\""}], "kilometers per hour", FractionBox["\"Kilometers\"", "\"Hours\""]}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.3549929`7.00176466057457, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{86., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)], t \[Distributed] GammaDistribution[3, \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "5 min", Typeset`boxes$$ = TemplateBox[{"5", "\"min\"", "minutes", "\"Minutes\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {{ "type" -> "Clash", "word" -> "min", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "3", "Values" -> {{ "name" -> "Unit", "desc" -> "a unit", "input" -> "*C.min-_*Unit-"}, { "name" -> "OptimizationWord", "desc" -> " referring to optimization", "input" -> "*C.min-_*OptimizationWord-"}, { "name" -> "HistoricalCountry", "desc" -> "a historical country", "input" -> "*C.min-_*HistoricalCountry-"}}}, { "type" -> "Unit", "word" -> "min", "template" -> "Assuming ${desc1} for \"${word}\". Use \ ${desc2} instead", "count" -> "3", "Values" -> {{ "name" -> "Minutes", "desc" -> "minutes of time", "input" -> "UnitClash_*min.*Minutes--"}, { "name" -> "MinimsUS", "desc" -> "US minims of volume", "input" -> "UnitClash_*min.*MinimsUS--"}, { "name" -> "ArcMinutes", "desc" -> "minutes of arc", "input" -> "UnitClash_*min.*ArcMinutes--"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.4070055`7.0611452715258896, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{101., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)]}]
Out[4]=

TransformedDistributionを使って確率変数の大きさを組み合せる.

In[5]:=
Click for copyable input
TransformedDistribution[QuantityMagnitude[t, "Celsius"], t \[Distributed] NormalDistribution[Quantity[293.15, "Kelvins"], Quantity[5.2, "Kelvins"]]]
Out[5]=

あるいは,Quantity[x, unit] の分布を定義して,x が確率変数の大きさを指定の unit で示すようにすることもできる.

In[6]:=
Click for copyable input
TransformedDistribution[t, Quantity[t, "Celsius"] \[Distributed] NormalDistribution[Quantity[293.15, "Kelvins"], Quantity[5.2, "Kelvins"]]]
Out[6]=

例えば,イリノイ州シカゴにおける冬季の気温と風速の分布を仮定して,華氏で北米の風速冷却度数の分布を表現する.

In[7]:=
Click for copyable input
wcTemp\[ScriptCapitalD] = TransformedDistribution[ 35.74 + 0.6215 QuantityMagnitude[Ta, "DegreesFahrenheit"] + (0.4275 QuantityMagnitude[Ta, "DegreesFahrenheit"] - 35.75) QuantityMagnitude[V, "Miles"/"Hours"]^+0.16, {V \[Distributed] WeibullDistribution[2.81, \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "4.846 m/s", Typeset`boxes$$ = TemplateBox[{"4.846", RowBox[{"\"m\"", " ", "\"/\"", " ", "\"s\""}], "meters per second", FractionBox["\"Meters\"", "\"Seconds\""]}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {{ "type" -> "MultiClash", "word" -> "", "template" -> "Assuming ${word1} is referring to ${desc1}. \ Use \"${word2}\" as ${desc2}.", "count" -> "2", "Values" -> {{ "name" -> "Unit", "word" -> "m/s", "desc" -> "a unit", "input" -> "*MC.m%2Fs-_*Unit-"}, { "name" -> "Variable", "word" -> "m", "desc" -> "a variable", "input" -> "*MC.m%2Fs-_*Variable-"}}}, { "type" -> "Unit", "word" -> "m/s", "template" -> "Assuming ${desc1} for \"${word}\". Use \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "MetersPerSecond", "desc" -> "meters per second", "input" -> "UnitClash_*m%2Fs.*MetersPerSecond--"}, { "name" -> "MinutesPerSecond", "desc" -> "minutes per second", "input" -> "UnitClash_*m%2Fs.*MinutesPerSecond--"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.5190047`7.166716284243896, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{133., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)], Ta \[Distributed] TriangularDistribution[{\!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "20 Fah", Typeset`boxes$$ = TemplateBox[{ "20", "\"\[Degree]F\"", "degrees Fahrenheit", "\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.5190113`7.166721806978768, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{78., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\), \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "48 Fah", Typeset`boxes$$ = TemplateBox[{ "48", "\"\[Degree]F\"", "degrees Fahrenheit", "\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 1.3720224`7.588906195330978, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{78., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)}, \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = "30 Fah", Typeset`boxes$$ = TemplateBox[{ "30", "\"\[Degree]F\"", "degrees Fahrenheit", "\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.2719958`6.8861071914606615, "Messages" -> {}}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, Dynamic[Typeset`query$$], Dynamic[Typeset`boxes$$], Dynamic[Typeset`allassumptions$$], Dynamic[Typeset`assumptions$$], Dynamic[Typeset`open$$], Dynamic[Typeset`querystate$$]], StandardForm], ImageSizeCache->{78., {8., 16.}}, TrackedSymbols:>{ Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{Typeset`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)]}]
Out[7]=

母集団標本からの風速冷却度数の平滑カーネル密度推定をプロットする.

完全なWolfram言語入力を表示する
In[8]:=
Click for copyable input
SmoothHistogram[RandomVariate[wcTemp\[ScriptCapitalD], 10^5], Filling -> Axis, AxesLabel -> {"\[Degree]F"}, Epilog -> {Directive[Dashed, Red], InfiniteLine[{{32, 0}, {32, 1}}]}]
Out[8]=

関連する例

de en es fr ko pt-br ru zh