Let's return to our scatter plot that summarized the relationship between
age and mean friend count. Recall that we ended up creating this
plot from the new data frame that we created using the
d ply r package. The plot looked like this. As you can
see, the black line has a lot of random noise to
it. That is, the mean friend count rises and falls over each
age. Let's print out some of our data frame to have
a closer look. As we can see, the mean friend count increases,
then decreases later. In one particular case, we can see
that for 30 year olds, the mean friend count is
actually lower compared to the 29 year olds and the
31 year olds. Now some year to year discontinuities might make
sense, such as the spike at age 69. But others
are likely just to be noise around the true smoother
relationship between age and friend count. That is, they reflect
that we just have a sample from the data generating process.
And so the estimated mean friend count for each age
is the true mean plus some noise. We can imagine
that the noise for this plot would be worse if
we chose finer bins for age. For example, we could estimate
conditional means for each age, measured in months instead of
years. Over the next few programming exercises, you're going to
do just that. You're going to create a plot just like
this one with a new variable that measures ages in months
instead of years. Then you'll plot the conditional mean for
ages in months, and we'll compare this graph to the
one that you create. To start, you're going to create
the age with months variable, and save it into the data
frame. This variable will have each user's age measured in
months rather than in years. So, if a user is 36
years old and was born in March, the user's age
would be 36.75. Try coding this up in R for yourself.
And then once you have the code, copy and
paste it into the browser and submit. Now, this is
one of the exercises where the grader will automatically
check your output. Don't worry if you don't get this
one right on your first try. It's pretty tough.
I really recommend thinking about ages and people being born
in different months. How would that affect the variable age
with months? Working with actual values might help you here.
فلنرجع إلى الرسم المبعثر لدينا والذي لخص العلاقة بين
العمر ومتوسط عدد الأصدقاء. ونفترض أننا انتهينا من إنشاء هذا الرسم
من إطار البيانات الجديد الذي قمنا بإنشائه باستخدام
حزمة d ply r. وظهر الرسم هكذا. وكما ترون
يوجد الكثير من التشويش العشوائي على الخط ،
الأسود. وهذا هو متوسط عدد الأصدقاء، يرتفع وينخفض عند كل
عمر. دعونا نطبع إطار بيانات معين لدينا لنحصل على صورة
،مقربة. فكما نلاحظ، يزيد متوسط عدد الأصدقاء
،ثم يقل بعد ذلك. وفي حالة واحدة خاصة
نرى أنه بالنسبة لأعمار ال30، يقل متوسط عدد الأصدقاء
بالفعل مقارنة بالأعمار ال29
،وال31. والآن، قد تكون بعض التوقفات من عام إلى عام لها دلالة
مثل الارتفاع عند عمر ال69، ولكن من المرجح ،
أن يكون البعض الآخر مجرد تشويش حول العلاقة الصحيحة
الأكثر سلاسة بين العمر وعدد الأصدقاء. وهذا يعني أنها تعكس
.أن لدينا مجرد عينة من عملية توليد البيانات
إذن المتوسط التقديري لعدد الأصدقاء لكل عمر
هو المتوسط الصحيح زائد بعض التشويش. ونتخيل أن
الضجيج لهذا الرسم سيكون أسوأ
إذا اخترنا فئات أدق للعمر. فعلى سبيل المثال، يمكننا تقدير
المتوسطات الشرطية لكل عمر، مقاسة بالشهور بدلاً من
السنين. وخلال تمارين البرمجة القليلة التالية، ستفعلون
ذلك فقط. حيث ستقومون بإنشاء رسم معين تمامًا كهذا
باستخدام متغير جديد يقيس الأعمار بالشهور
بدلاً من السنين. ثم سترسمون المتوسط الشرطي
للأعمار بالشهور، وسنقارن هذا الرسم البياني
بذلك الرسم البياني الذي قمتم بإنشائه. للبدء، ستقومون بإنشاء
متغير العمر بالشهور، وحفظه في إطار
البيانات. وسيحتوي هذا المتغير على عمر كل مستخدم مقاسًا
بالشهور بدلاً من السنين. وإذا كان عمر مستخدم ما 36 عامًا
وولد في مارس، فسيصبح عمره
.36.75. حاولوا تكوين هذه التعليمة البرمجية في R لأنفسكم
وبمجرد أن تحصوا على التعليمة البرمجية، تأكدوا من نسخها
ولصقها في المستعرض وتقديمها. الآن، هذا هو
أحد التمارين الذي فيه ستتحقق الدرجة تلقائيًا
من مخرجاتكم. لا تقلقوا في حالة عدم استيعابكم
.هذا مباشرة في أول محاولة لكم. إنه صعب جدًا
أوصيكم بشدة بالتفكير في الأعمار والأفراد الذين يولدون
في شهور مختلفة. كيف سيؤثر ذلك على المتغير age
.بالشهور؟ قد يساعدكم التعامل مع القيم الفعلية هنا
年齢と友達数の平均値の関連性を
要約した散布図に戻りましょう
この図はdplyrパッケージを使用して作成した
新しいデータフレームで作りました
図はこのようになっています
黒い線にランダムなノイズが多数あります
これは友達数の平均値が年齢で上下しているためです
さらにデータを見ていきましょう
ご覧のように友達数の平均値はまず上昇し
そのあと下降しています このケースでは
30歳のユーザの友達数の平均値は
29歳と31歳に比べ低くなっています
69歳の突出した波形など年ごとの不連続性は
理解できるかもしれません
しかし他のものは年齢と友達数の
実際の円滑な関連性の周囲にある
ただのノイズのようです
それはこれがデータ作成プロセスのサンプルだからです
各年齢ごとの友達数の推定平均値は
本当の平均値にノイズがプラスされたものです
年齢の幅を細かくするとこのノイズが
さらにひどくなると予測できます
例えば各年齢の条件付平均値を推測し
月単位で計測することも可能です
これは今後数回のプログラミング問題で練習します
年単位ではなく月単位で計測された
新しい変数を使いこのような図を作成するのです
さらに月数を数えた年齢ごとの条件付平均値を作図し
このグラフと比べていきます
はじめに年齢と月数の変数を作り
データフレームに保存しましょう
この変数はユーザの年齢を
年数と月数で測定したものです
つまりユーザが36歳の3月生まれだとしたら
ユーザの年齢は36.75となります
Rでこのコードを書いてみてください
できたらコピーをブラウザにペーストし
提出してください
これは自動採点の練習問題です
一発で正解できなくても大丈夫です
これはかなり難しい問題ですからね
年齢と人々の誕生月が違うことを考慮しましょう
それがどう年齢と月数の変数に影響するか
実際の値でやってみるといいでしょう
Vamos retornar ao nosso gráfico de dispersão que resumiu a relação entre
idade e contagem média de amigos. Lembre-se de que acabamos criando este
gráfico a partir da nova estrutura de dados que criamos usando o pacote
dplyr. O gráfico era assim. Como você pode
ver, a linha preta tem muito ruído aleatório
. Ou seja, a contagem média de amigos sobe e desce em cada
idade. Vamos imprimir parte da nossa estrutura de dados para
um olhar mais atento. Como podemos ver, a contagem média de amigos aumenta e,
em seguida, diminui. Em um caso específico, podemos ver
que para pessoas com 30 anos, a contagem média de amigos é,
na verdade, mais baixa comparada à de pessoas de 29 e
31 anos. Talvez, algumas descontinuidades de ano em ano possam fazer
sentido, como o pico aos 69 anos. Mas outros
têm mais probabilidade de serem apenas ruídos em uma relação
mais suave entre idade e contagem de amigos. Ou seja, eles refletem
que nós temos apenas uma amostra do processo de geração de dados.
Dessa forma, a contagem média estimada de amigos para cada idade
é a média verdadeira mais algum ruído. Podemos imaginar
que o ruído para este gráfico seria pior se
escolhêssemos colunas mais específicas para idade. Por exemplo, poderíamos estimar
médias condicionais para cada idade, medidas em meses em vez de
anos. Nos próximos exercícios de programação, você
fará isso. Você criará um gráfico como
este com uma nova variável que mede idades em meses
em vez de anos. Em seguida, fará um gráfico da média condicional para
idades em meses e o compararemos a
este gráfico. Para começar, você criará
a variável de idade com meses e a salvará na estrutura de
dados. Esta variável terá a idade de cada usuário medida em
meses, e não em anos. Então, se um usuário tiver 36
anos e tiver nascido em março, a idade dele
será 36,75. Tente programar este código no R sozinho.
E quando o código estiver pronto, copie-o e
cole-o no navegador e envie. Este é
um dos exercícios em que o graduador verificará
sua saída automaticamente. Não se preocupe se você não conseguir
acertar em sua primeira tentativa. É bem difícil.
Realmente recomendo pensar sobre as idades e as pessoas nascendo
em meses diferentes. Como isso afetaria a idade da variável
com meses? Trabalhar com valores reais pode ajudá-lo aqui.
我们回到这个汇总年龄和平均好友数关系的散点图
记得我们最终使用 d ply r 程序包
所创建的新数据帧生成了这幅图
这幅图像这个样子
可以看出 黑线有很多随机噪声
也就是说 平均好友数在每个年龄上升降
我们打印出一些数据帧来详细观察
可以看出 平均好友数上升
然后在以后下降 在具体例子中可以看出
对于 30 岁年龄 平均好友数
实际上低于 29 岁和 31 岁
部分的年同比不连续性可能说得过去
比如在年龄 69 岁的尖峰
但其它很可能就是
围绕年龄和好友数真实平滑关系的噪声 也就是说反映出
我们只从数据生成流程中得到一个样本
所以每个年龄的预估平均好友数
是真实平均值加上一些噪声
我们可以想象 如果选择更精细的年龄容器
这幅图的噪声会更糟一些 例如
我们可以估计每个年龄的条件平均值 单位用月份代替年份
在下面几个编程练习中 你会做这个
你将使用新的变量创建类似这样的图形
其中的年龄单位是月份而不是年份
然后将按照月龄绘制条件平均值
然后将这幅图与你生成的图对比
开始时 创建的是含月份的年龄变量
将其保存到数据帧内
这个变量所含的是每个用户用月份度量的年龄
而不是按年份 所以 如果用户为 36 岁
出生于三月 那么用户的年龄就是
36.75 岁 尝试在 R 中自己编写这个代码
完成这段代码后
复制并粘贴到浏览器中提交
这是其中一个练习 评分器将自动检查你的输出
如果你第一次尝试未能做对
也不要担心 这个有点难度
我建议你考虑年龄和不同的生月
会如何影响含月份的年龄变量
使用实际值会对你有所帮助