HW 1

## 'data.frame':    200 obs. of  11 variables:
##  $ id     : int  70 121 86 141 172 113 50 11 84 48 ...
##  $ female : chr  "male" "female" "male" "male" ...
##  $ race   : chr  "white" "white" "white" "white" ...
##  $ ses    : chr  "low" "middle" "high" "high" ...
##  $ schtyp : chr  "public" "public" "public" "public" ...
##  $ prog   : chr  "general" "vocation" "general" "vocation" ...
##  $ read   : int  57 68 44 63 47 44 50 34 63 57 ...
##  $ write  : int  52 59 33 44 52 52 59 46 57 55 ...
##  $ math   : int  41 53 54 47 57 51 42 45 54 52 ...
##  $ science: int  47 63 58 53 53 63 53 39 58 NA ...
##  $ socst  : int  57 61 31 56 61 61 61 36 51 51 ...
## [1] 200  11
##    id female  race    ses schtyp     prog read write math science socst
## 1  70   male white    low public  general   57    52   41      47    57
## 2 121 female white middle public vocation   68    59   53      63    61
## 3  86   male white   high public  general   44    33   54      58    31
## 4 141   male white   high public vocation   63    44   47      53    56
## 5 172   male white middle public academic   47    52   57      53    61
## 6 113   male white middle public academic   44    52   51      63    61

(a) test if any pairs of the five variables: read, write, math, science, and socst, are different in means.

## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  res$value and res$variable 
## 
##         read write math science
## write   0.58 -     -    -      
## math    0.68 0.90  -    -      
## science 0.76 0.39  0.47 -      
## socst   0.86 0.71  0.81 0.63   
## 
## P value adjustment method: none

no significant difference between all paris of five variable ## (b) test if the 4 different ethnic groups have the same mean scores for each of the 5 variables (individually): read, write, math, science, and socst.

## $read
## Analysis of Variance Table
## 
## Response: x$value
##                 Df  Sum Sq Mean Sq F value    Pr(>F)    
## factor(x$race)   3  1749.8  583.27  5.9637 0.0006539 ***
## Residuals      196 19169.6   97.80                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $write
## Analysis of Variance Table
## 
## Response: x$value
##                 Df  Sum Sq Mean Sq F value    Pr(>F)    
## factor(x$race)   3  1914.2  638.05  7.8334 5.785e-05 ***
## Residuals      196 15964.7   81.45                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $math
## Analysis of Variance Table
## 
## Response: x$value
##                 Df  Sum Sq Mean Sq F value   Pr(>F)    
## factor(x$race)   3  1842.1  614.05  7.7033 6.84e-05 ***
## Residuals      196 15623.7   79.71                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $science
## Analysis of Variance Table
## 
## Response: x$value
##                 Df  Sum Sq Mean Sq F value    Pr(>F)    
## factor(x$race)   3  3169.5 1056.51  13.063 8.505e-08 ***
## Residuals      191 15447.2   80.88                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## $socst
## Analysis of Variance Table
## 
## Response: x$value
##                 Df  Sum Sq Mean Sq F value  Pr(>F)  
## factor(x$race)   3   943.9  314.63   2.804 0.04098 *
## Residuals      196 21992.3  112.21                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

mean of scores are significantly different between groups

(c) Perform all pairwise simple regressions for these variables: read, write, math, science, and socst.

## $read
##                      [,1]       [,2]       [,3]       [,4]       [,5]
## (Intercept) -8.141284e-15 24.4095462 21.2425264 20.6602830 18.5561875
## x            1.000000e+00  0.5425249  0.6009356  0.5998076  0.6476622
## 
## $write
##                   [,1]          [,2]       [,3]       [,4]       [,5]
## (Intercept) 18.7309118 -8.955412e-14 20.6572869 21.1309429 16.5279046
## x            0.6336486  1.000000e+00  0.6055514  0.5843927  0.6791647
## 
## $math
##                   [,1]       [,2] [,3]     [,4]       [,5]
## (Intercept) 14.5396491 20.2651022    0 17.49497 19.9529454
## x            0.7148764  0.6167729    1  0.65494  0.6155894
## 
## $science
##                   [,1]       [,2]       [,3]          [,4]       [,5]
## (Intercept) 18.1571108 24.3565993 21.3916641 -8.141284e-15 26.1686196
## x            0.6540264  0.5455811  0.6003186  1.000000e+00  0.5034689
## 
## $socst
##                   [,1]      [,2]       [,3]       [,4]         [,5]
## (Intercept) 21.5368195 25.229771 28.1291585 30.1197077 1.628257e-14
## x            0.5845412  0.524823  0.4670406  0.4167311 1.000000e+00

HW 2

The formula P = L (r/(1-(1+r)^(-M)) describes the payment you have to make per month for M number of months if you take out a loan of L amount today at a monthly interest rate of r. Compute how much you will have to pay per month for 10, 15, 20, 25, or 30 years if you borrow NT$5,000,000, 10,000,000, or 15,000,000 from a bank that charges you 2%, 5%, or 7% for the monthly interest rate.

##          [,1]     [,2]     [,3]
## [1,] 110240.5 220481.0 330721.5
## [2,] 102913.7 205827.4 308741.0
## [3,] 100870.4 201740.8 302611.2
## [4,] 100263.7 200527.4 300791.1
## [5,] 100080.2 200160.4 300240.7
##          [,1]     [,2]     [,3]
## [1,] 250718.6 501437.1 752155.7
## [2,] 250038.4 500076.7 750115.1
## [3,] 250002.1 500004.1 750006.2
## [4,] 250000.1 500000.2 750000.3
## [5,] 250000.0 500000.0 750000.0
##          [,1]     [,2]    [,3]
## [1,] 350104.3 700208.5 1050313
## [2,] 350001.8 700003.6 1050005
## [3,] 350000.0 700000.1 1050000
## [4,] 350000.0 700000.0 1050000
## [5,] 350000.0 700000.0 1050000
## [[1]]
##          [,1]     [,2]     [,3]
## [1,] 110240.5 220481.0 330721.5
## [2,] 102913.7 205827.4 308741.0
## [3,] 100870.4 201740.8 302611.2
## [4,] 100263.7 200527.4 300791.1
## [5,] 100080.2 200160.4 300240.7
## 
## [[2]]
##          [,1]     [,2]     [,3]
## [1,] 250718.6 501437.1 752155.7
## [2,] 250038.4 500076.7 750115.1
## [3,] 250002.1 500004.1 750006.2
## [4,] 250000.1 500000.2 750000.3
## [5,] 250000.0 500000.0 750000.0
## 
## [[3]]
##          [,1]     [,2]    [,3]
## [1,] 350104.3 700208.5 1050313
## [2,] 350001.8 700003.6 1050005
## [3,] 350000.0 700000.1 1050000
## [4,] 350000.0 700000.0 1050000
## [5,] 350000.0 700000.0 1050000

don’t know why list r did not work

HW 3

The following R script is an attempt to demonstrate the correspondence between parameter estimations by the least square method and the maximum likelihood method for the case of simple linear regression with a constant normal error term. 1. Construct a function from the script so that any deviance value for pairs of parameter estimates can be found. 2. Generalize the function further so that it will work with any data sets that can be modeled by a simple linear regression with a constant normal error term.

## 
## Call:
## lm(formula = weight ~ height, data = women)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7333 -1.1333 -0.3833  0.7417  3.1167 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -87.51667    5.93694  -14.74 1.71e-09 ***
## height        3.45000    0.09114   37.85 1.09e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.525 on 13 degrees of freedom
## Multiple R-squared:  0.991,  Adjusted R-squared:  0.9903 
## F-statistic:  1433 on 1 and 13 DF,  p-value: 1.091e-14
## (Intercept)           x 
##   -87.51667     3.45000 
## [1] 1.525005
##  [1] 0.07452923 0.21398769 0.24700963 0.26135075 0.25346523 0.22531900
##  [7] 0.18359549 0.13712321 0.19359472 0.14741642 0.20326265 0.24608202
## [13] 0.26158497 0.15433520 0.03240932
## [1] 53.22809