Now that we have a better understanding of our variables, and
the overall demand for diamonds, let's replot the data. This time
we'll put price on a log10 scale, and here's what it
looks like. This plot looks better than before. On the log
scale, the prices look less dispersed at the high end of
Carat size and price, but actually we can do better. Let's
try using the cube root of Carat in light of our
speculation about flaws being exponentially more
likely in diamonds with more volume.
Remember, volume is on a cubic scale. First, we need
a function to transform the Carat variable. If you'd like to
learn more about writing your own functions in R, check out
the links in the instructor notes. This may seem like a
lot of code, but really, there's only one new piece here.
It's this cube root trans-function. It's a function that takes the
cube root of any input variable, and it also has an
inverse function to undo that operation, which we need to display
the plot correctly. Then when we get to
our actual ggplot command. What we'll do is we'll
use the scale_x_continuous argument to transform the x
axis with this cube root transformation function. Keep in
mind we're also transforming the y axis with
this log10 transformation that we discussed previously. And, let's
see what this plot looks like. Taking a
look at the plot, we can actually see that
with these transformations that we used to get
our data on this nice scale. Things look almost
linear. We can now move forward and see
about modelling our data using just a linear model.
،الآن، وبعد حصولنا على فهم أفضل لمتغيراتنا
،وإجمالي الطلب على الماس، فلنُعد رسم البيانات. في الوقت الحالي
سنضع سعرًا على مقياس log10، وهنا
،الشكل الذي يظهر به. هذا الرسم يبدو أفضل من ذي قبل. وعلى مقياس التسجيل
تبدو الأسعار أقل تبعثرًا عند الحد الأعلى
لحجم القيراط وسعره، لكننا حقًا يمكننا أن نفعل أفضل. فلنحاول
استخدام الجذر التكعيبي للقيراط في ضوء
تكهناتنا حول العيوب التي من المحتمل أن تزداد بدرجة كبيرة
.مع تزايد حجم الماس
تذكر أن الحجم بمقياس تكعيبي. أولاً، نحتاج إلى
دالة معينة لتحويل متغير القيراط. وإذا كنتم تريدون
،معرفة المزيد عن كتابة الدوال في R
فُيرجى الرجوع إلى الروابط الواردة في ملاحظات المدرب. قد يبدو هذا أكثر من تعليمة برمجية
.لكن بالفعل، يوجد فقط واحد فقط جديد هنا ،
ها هي دالة تحويل الجذر التكعيبي. إنها دالة تأخذ
الجذر التكعيبي لأي متغير إدخال، كما تحتوي أيضًا على
دالة عكسية للتراجع عن تلك العملية، التي نحتاج إلى عرض
الرسم فيها بشكل صحيح. وبعد ذلك، عندما نصل إلى
أمر ggplot الفعلي. ما سنفعله هو أننا
سنستخدم الوسيطة scale_x_continuous لتحويل المحور x
باستخدام دالة تحويل الجذر التكعيبي هذه. ضعوا في اعتباركم
أننا نقوم أيضًا بتحويل المحور y
باستخدام التحويل log10 هذا الذي ناقشناه من قبل. فلنرِ
كيف يبدو هذا الرسم. بالنظر إلى
الرسم، يمكننا أن نرى بالفعل أنه
من خلال هذه التحويلات التي استخدمناها
للحصول على بياناتنا على هذا المقياس الرائع. تبدو الأشياء خطية
تقريبًا. يمكننا الآن المضي قدمًا والاطلاع على
.إنشاء نماذج للبيانات باستخدام نموذج خطي فحسب
変数とダイヤモンドの総需要について
理解が深まったと思います
データを再プロットしてみましょう
価格をlog10目盛にしました このようになります
前よりも見やすくなりました
対数目盛では横軸の右端において
価格の分散は小さいようです
でももっと分かりやすくできます
より体積の大きいダイヤモンドに
キズが生じる確率は指数関数的に
増えるだろうという私たちの推測を踏まえて
カラットの立方根を使います
体積の単位は3条のオーダーです
カラットの変数に変換する関数が必要です
R言語の関数の書き方を勉強したい場合は
インストラクターノートのリンクから確認してください
たくさんのコードが書いてありますが
新しいものはこれだけです
cuberoot_trans関数です
入力の値の立方根をとる関数です
図を正しく表示する必要があるので
操作を取り消す働きをするinverse関数も用意します
ggplotコマンドに戻ります
scale_x_continuous引数を使って
x軸をcuberoot_trans関数で変換します
y軸も前にお話した
log10 transformationで変換します
どうなるでしょうか
図を見てみましょう
この目盛でデータを表すために使った変換で
見ることができます
ほぼ線形に見えます
次に進みましょう
線形モデルを使った
データのモデル化について見ていきます
Agora que entendemos melhor nossas variáveis e demanda
geral de diamantes, vamos traçar os dados novamente. Desta vez,
colocaremos um preço em uma escala log10, ficando
assim. O gráfico ficou melhor que antes. Na escala
de log, os preços parecem menos dispersos no alto
de tamanho e preço do quilate, mas podemos fazer melhor. Vamos
tentar usar a raiz cúbica de quilate considerando
nossa especulação de que falhas sejam
mais prováveis em diamantes com mais volume.
O volume está em uma escala cúbica. Primeiro, precisamos
que uma função transforme a variável carat. Se você quiser
saber mais sobre como criar suas próprias funções em R, consulte
os links nas Notas do instrutor. Isso pode parecer muito
código, mas temos apenas uma parte dele aqui.
É a transfunção raiz cúbica. É uma função que considera
a raiz cúbica de qualquer variável de entrada e tem
uma função inversa para desfazer a operação, que precisamos
exibir no gráfico corretamente. Então, chegamos ao
nosso comando ggplot. O que faremos é
usar o argumento scale_x_continuous para transformar o eixo x
com essa função de transformação da raiz cúbica. Lembre-se
de que também estamos transformando o eixo y
com a transformação log10 discutida anteriormente. Vamos ver
como ficará esse gráfico. Analisando
o gráfico, vemos que, com essas transformações
que usamos para obter nossos dados
nessa escala, tudo parece quase
linear. Agora podemos continuar e ver
sobre como modelar nossos dados usando um modelo linear.
现在我们对变量以及钻石的整体需求有了更好的了解
我们来重新绘制数据图
这次 我使用 log10 标度表示价格 就像这样
这幅图看起来比以前好了不少
在对数标度上 价格在克拉大小和价格的高端离散较小
但实际上我们还能做的更好
我们尝试使用克拉的立方根 因为我们猜测
钻石随着数量增加
瑕疵可能呈指数增加
记住 数量是立方标度 首先我们需要一个函数
来转换克拉变量
如果你想要在 R 中编写自己的函数
请查看讲师注释中的这个链接
看起来好像很多代码 但实际上这里只有一个新东西
就是这个立方根转换函数 这个函数取
所有输入变量的立方根 它还有一个
用于撤销该运算的反函数 用来正确显示绘图
然后我们使用
实际的 ggplot 命令 我们要做的就是
使用 scale_x_continuous 自变量
通过这个立方根转换函数来转换 x 轴
记住我们同时使用这个以前讨论的 log10 变换
来转换 y 轴
我们看看这幅图会是什么样
看一下这幅图 我们实际上看到
通过这些变换
可以在这种漂亮的标度上表现我们的数据
看起来几乎呈现线性关系 现在可以继续
考虑使用线性模型来为数据建模