Doing Bayesian with R: Assigment 3


output:
html_notebook: default


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

你可能感兴趣的:(Doing Bayesian with R: Assigment 3)