Doing Bayesian with R: Assigment 3


output:
html_notebook: default


<style type="text/css">
body{ /* Normal / font-size: 14px}
td { /
Table / font-size: 10px}
h1 { /
Header 1 / font-size: 24px}
h2 { /
Header 2 / font-size: 20px}
h3 { /
Header 3 / font-size: 16px}
code.r{ /
Code block / font-size: 14px}
pre { /
Code block */ font-size: 14px}
</style>

BDA Assignment 3 (24 pts)

Exercise 3.0 (not in text) 5 points

List the technical terms you encountered in this chapter, with a '?' after those you have not encountered before. Look up at least one of the terms that are new to you---Wikipedia is always a good place to begin---and give a definition that makes sense to you.

Exercise 3.2, page 70, (I give you the answer.)

One answer to this exercise is to drag the code chunk to the console and run it there. The resulting plot will appear in the RStudio plots pane. In that pane there is an "Export" button which gives you a pull-down menu to select the export format you would like.
An even better way, since you might want to make the plot again sometime, is to save the code chunk as an R-script. Press the "new" button in the upper left corner of the RStudio window (the leftmost button, the one that looks like a tiny sheet of paper with a white plus sign on a green dot) and drop the code chunk into your new script. Then press the run button and export the resulting plot.

Exercise 3.3, page 70, 6 points

Answer here, in text and code chunk(s). Use the title( ) function to put a title on your plot and explicitly label the axes.

Exercise 3.4 (not in our text), 5 points

Read the Kruschke supplied file HGN.csv with the statement datFram = read.csv( "HGN.csv" ). Then:
a. Display the first three rows of the data frame using explicit numerical indexing of rows in bracket notation.
b. Display the first three rows of the data frame using the head() function.
c. What is the class (e.g., factor, integer, etc.) of the $group component of the data frame? Use the class() function.
d. Change the $group component to a factor, using the factor() function, and display the result with its levels.
e. Display the Hair component of the data frame by referring to it three different ways: Using $ notation, using brackets with column name, and using brackets with column number.

Exercise 3.5 (not in our text), 8 points

Create a function in R that converts Fahrenheit temperatures to Celsius temperatures. Set the default input temperature to 72. Hint: C = (F- 32)*5/9.
A. Show the specification of the function.
B. Run the function with no explicit input, to reveal its default output.
C. Run the function with 98.6 as its input.
D. Run the function with the vector c( 32 , 72 , 98.6 , 212 ) as its input. Very briefly explain why the function produces a vector as output.

Et cetera department

(If you have a question, or a suggestion for class, tell me here.)

The flowing is my solutions


title: "R Notebook"
output: html_notebook


Exercise 3.0

  1. function all.equal : for testing equality up to the degree of precision for the computer being used.
  2. three ways to reference elements: by numerical position, by logical inclusion, and by name.
  3. array data structure: a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored so that the position of each element can be computed from its index tuple by a mathematical formula.
  4. data frame: much like a matrix, insofar as it has several columns of equal length. But each column can be of a different type, and, in particular, columns can be factors.

Exercise 3.2

source("DBDA2E-utilities.R")             # read defn. of openGraph, saveGraph
openGraph( width=3 , height=4 )          # open a graphics window
plot( x=1:4 , y=c(1,3,2,4) , type="o" )  # make a plot in the screen window
saveGraph( file="temp" , type="pdf" )    # save the graph as "temp.pdf"

Exercise 3.3

x = seq( from = -3 , to = 3 , by = 0.1 )   # Specify vector of x values.
y = x^3                                    # Specify corresponding y values.
plot( x , y , col="skyblue" , type="l", main="SimpleGraph", xlab="x", ylab="y" )   # Plot the x,y points as a blue line.
dev.copy2eps(file="SimpleGraph.eps")       # Save the plot as .eps

Exercise 3.4

datFram=read.csv("HGN.csv")                # Read csv
datFram[1:3,]                              # Numerical indexing of first three rows
head(datFram,n=-4L)                        # Head() function

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,456评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,370评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,337评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,583评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,596评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,572评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,936评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,595评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,850评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,601评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,685评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,371评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,951评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,934评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,167评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,636评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,411评论 2 342

推荐阅读更多精彩内容