0323 HW1-HW4

Huei Jiuan Wu

March 29, 2019

HW Exercise 0323-1

Here is a copy of the student roster in csv format from NCKU for a course I taught. Dispaly the number of students from each major.

Loading and display the number of students from each major

## 
## 心理系 心理所 教育所 
##      4      7      4

HW Exercise 0323-2

Display the relationship between Income and Taxes

#Loading data and check data structure

## 'data.frame':    38 obs. of  8 variables:
##  $ City  : Factor w/ 38 levels "Atlanta","Austin",..: 1 2 3 4 5 6 7 9 8 10 ...
##  $ COL   : int  169 143 339 173 99 363 253 117 294 291 ...
##  $ PD    : int  414 239 43 951 255 1257 834 162 229 1886 ...
##  $ URate : num  13.6 11 23.7 21 16 24.4 39.2 31.5 18.2 31.5 ...
##  $ Pop   : int  1790128 396891 349874 2147850 411725 3914071 1326848 162304 164145 7015251 ...
##  $ Taxes : int  5128 4303 4166 5001 3965 4928 4471 4813 4839 5408 ...
##  $ Income: int  2961 1711 2122 4654 1620 5634 7213 5535 7224 6113 ...
##  $ RTWL  : int  1 1 0 0 1 0 0 0 1 0 ...

#examing the realtionship between Income and Taxes

## 
##  Pearson's product-moment correlation
## 
## data:  dta$Income and dta$Taxes
## t = 0.33696, df = 36, p-value = 0.7381
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2684231  0.3691383
## sample estimates:
##       cor 
## 0.0560718

p-value of correlation test is >0.05. Hence, Income is not siginificantly correlated with taxes.

HW Exercise 0323-3

Download the data file in junior school project and read it into your currect R session. Assign the data set to a data frame object called jsp. (1) Re-name the variable ‘sex’ as ‘Gender’. (2) Re-label the values of the social class variable using the (long character strings) descriptive terms to produce the following plot. (3) Save the edited jsp data object out as a comma-separated-value file and in a R data format to a data folder and read them back into your R session, separately.

#Loading data and as a data frame

## 'data.frame':    3236 obs. of  9 variables:
##  $ school : chr  "S1" "S1" "S1" "S1" ...
##  $ class  : chr  "C1" "C1" "C1" "C1" ...
##  $ sex    : chr  "G" "G" "G" "B" ...
##  $ soc    : int  9 9 9 2 2 2 2 2 9 9 ...
##  $ ravens : int  23 23 23 15 15 22 22 22 14 14 ...
##  $ pupil  : chr  "P1" "P1" "P1" "P2" ...
##  $ english: int  72 80 39 7 17 88 89 83 12 25 ...
##  $ math   : int  23 24 23 14 11 36 32 39 24 26 ...
##  $ year   : int  0 1 2 0 1 0 1 2 0 1 ...

#(1) Re-name the variable ‘sex’ as ‘Gender’.

## 'data.frame':    3236 obs. of  9 variables:
##  $ school : chr  "S1" "S1" "S1" "S1" ...
##  $ class  : chr  "C1" "C1" "C1" "C1" ...
##  $ Gender : chr  "G" "G" "G" "B" ...
##  $ soc    : int  9 9 9 2 2 2 2 2 9 9 ...
##  $ ravens : int  23 23 23 15 15 22 22 22 14 14 ...
##  $ pupil  : chr  "P1" "P1" "P1" "P2" ...
##  $ english: int  72 80 39 7 17 88 89 83 12 25 ...
##  $ math   : int  23 24 23 14 11 36 32 39 24 26 ...
##  $ year   : int  0 1 2 0 1 0 1 2 0 1 ...

#(2) Re-label the values of the social class variable using the (long character strings) descriptive terms to produce the following plot.

## [1] "I"             "II"            "III_0man"      "III_man"      
## [5] "IV"            "V"             "VI_Unemp_L"    "VII_emp_NC"   
## [9] "VIII_Miss_Dad"
## 'data.frame':    3236 obs. of  9 variables:
##  $ school : chr  "S1" "S1" "S1" "S1" ...
##  $ class  : chr  "C1" "C1" "C1" "C1" ...
##  $ Gender : chr  "G" "G" "G" "B" ...
##  $ soc    : Factor w/ 9 levels "I","II","III_0man",..: 9 9 9 2 2 2 2 2 9 9 ...
##  $ ravens : int  23 23 23 15 15 22 22 22 14 14 ...
##  $ pupil  : chr  "P1" "P1" "P1" "P2" ...
##  $ english: int  72 80 39 7 17 88 89 83 12 25 ...
##  $ math   : int  23 24 23 14 11 36 32 39 24 26 ...
##  $ year   : int  0 1 2 0 1 0 1 2 0 1 ...

  1. Save the edited jsp data object out as a comma-separated-value file and in a R data format to a data folder and read them back into your R session, separately.

read the data back into R session and show the first 6 rows

##   school class Gender           soc ravens pupil english math year
## 1     S1    C1      G VIII_Miss_Dad     23    P1      72   23    0
## 2     S1    C1      G VIII_Miss_Dad     23    P1      80   24    1
## 3     S1    C1      G VIII_Miss_Dad     23    P1      39   23    2
## 4     S1    C1      B            II     15    P2       7   14    0
## 5     S1    C1      B            II     15    P2      17   11    1
## 6     S1    C1      B            II     22    P3      88   36    0

##HW Exercise 0323-4 The following zip file contains one subject’s laser-event potentials (LEP) data for 4 separate conditions (different level of stimulus intensity), each in a plain text file (1w.dat, 2w.dat, 3w.dat and 4w.dat). The rows are time points from -100 to 800 ms sampled at 2 ms per record. The columns are channel IDs. Input all the files into R for graphical exploration.

Import zipped stata file

The zip files was not found on the server.