TASK :2a

starting_salaries <- read.csv(paste("MBA Starting Salaries Data.csv", sep=""))
View(starting_salaries)
attach(starting_salaries)
#people who have a certain salary which they have disclosed and given a rating of satisfaction also.
mytable <- subset.data.frame(starting_salaries, (salary!=998 & salary !=999))
View(mytable)
library(corrplot)
## corrplot 0.84 loaded
library(corrgram)
str(mytable)
## 'data.frame':    193 obs. of  13 variables:
##  $ age     : int  23 24 24 24 24 25 25 27 27 28 ...
##  $ sex     : int  2 1 1 1 1 1 2 1 1 2 ...
##  $ gmat_tot: int  620 610 670 570 640 610 650 740 750 540 ...
##  $ gmat_qpc: int  77 90 99 56 82 89 88 99 99 75 ...
##  $ gmat_vpc: int  87 71 78 81 89 74 89 96 98 50 ...
##  $ gmat_tpc: int  87 87 95 75 91 87 92 99 99 65 ...
##  $ s_avg   : num  3.4 3.5 3.3 3.3 3.9 3.4 3.3 3.5 3.4 3.6 ...
##  $ f_avg   : num  3 4 3.25 2.67 3.75 3.5 3.75 3.5 3.5 4 ...
##  $ quarter : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ work_yrs: int  2 2 2 1 2 2 2 3 1 5 ...
##  $ frstlang: int  1 1 1 1 1 1 1 1 2 1 ...
##  $ salary  : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ satis   : int  7 6 6 7 6 5 6 6 5 5 ...
boxplot(mytable$age, xlab= "age", ylab = "age", main= "age distribution", horizontal = TRUE)

boxplot(mytable$gmat_tot, xlab= "gmat_total", ylab = "gmat_total", main= "gmat_total distribution", horizontal = TRUE)

boxplot(mytable$gmat_qpc, xlab= "gmat_qpc", ylab = "gmat_qpc", main= "gmat_qpc distribution", horizontal = TRUE)

boxplot(mytable$gmat_vpc, xlab= "gmat_vpc", ylab = "gmat_vpc", main= "gmat_vpc distribution", horizontal = TRUE)

boxplot(mytable$gmat_tpc, xlab= "gmat_tpc", ylab = "gmat_tpc", main= "gmat_tpc distribution", horizontal = TRUE)

boxplot(mytable$s_avg, xlab= "s_avg", ylab = "s_avg", main= "s_avg distribution", horizontal = TRUE)

boxplot(mytable$f_avg, xlab= "f_avg", ylab = "f_avg", main= "f_avg distribution", horizontal = TRUE)

boxplot(mytable$work_yrs , xlab= "work_yrs ", ylab = "work_yrs ", main= "work_yrs  distribution", horizontal = TRUE)

boxplot(mytable$salary, xlab= "salary", ylab = "salary", main= "salary distribution", horizontal = TRUE)

boxplot(mytable$satis, xlab= "satis", ylab = "satis", main= "satis distribution", horizontal = TRUE)

plot(x = mytable$age, y=mytable$gmat_tot, xlab= "age", ylab = "gmat_tot")

plot(x = mytable$gmat_tot, y=mytable$salary, xlab= "gmat_tot", ylab = "salary")

plot(x = mytable$work_yrs, y=mytable$salary, xlab= "work_yrs", ylab = "salary")

plot(x = mytable$age, y=mytable$satis, xlab= "age", ylab = "satisfaction")

plot(x = mytable$salary, y=mytable$satis, xlab= "salary", ylab = "satisfaction")

plot(x = mytable$s_avg, y=mytable$salary, xlab= "s_avg", ylab = "salary")

library(corrplot)
library(corrgram)
cov(mytable)
##                    age           sex    gmat_tot      gmat_qpc
## age       1.778562e+01  -0.060503022  -29.954933   -14.0897291
## sex      -6.050302e-02   0.202558290   -1.107243    -1.1445110
## gmat_tot -2.995493e+01  -1.107243092 3196.950561   636.3509283
## gmat_qpc -1.408973e+01  -1.144511010  636.350928   229.3840674
## gmat_vpc -4.564443e-01   0.718776986  685.464432    42.7985481
## gmat_tpc -7.512764e+00  -0.078232945  672.465188   141.4933074
## s_avg     2.626913e-01   0.012515382    3.076706     0.1092870
## f_avg    -7.513817e-02   0.010030764    2.969557     1.0252407
## quarter  -3.567573e-01  -0.043042962   -5.248543     0.1438364
## work_yrs  1.355880e+01  -0.039561744  -36.222204   -13.4840782
## frstlang  1.105084e-01  -0.001025475   -1.450507     0.3843372
## salary   -2.918528e+04 442.963190846 -170.881369 22855.7178325
## satis    -2.399342e-01  -0.021507988    3.493361    -0.2345369
##              gmat_vpc      gmat_tpc         s_avg         f_avg
## age        -0.4564443 -7.512764e+00    0.26269133  -0.075138169
## sex         0.7187770 -7.823294e-02    0.01251538   0.010030764
## gmat_tot  685.4644322  6.724652e+02    3.07670553   2.969556887
## gmat_qpc   42.7985481  1.414933e+02    0.10928703   1.025240717
## gmat_vpc  259.2695920  1.498748e+02    1.16361534   0.276970261
## gmat_tpc  149.8747571  1.830114e+02    0.96881989   0.771858538
## s_avg       1.1636153  9.688199e-01    0.14365606   0.102512632
## f_avg       0.2769703  7.718585e-01    0.10251263   0.269959639
## quarter    -2.4783571 -1.919905e+00   -0.30776770  -0.219389573
## work_yrs   -2.4562014 -8.289778e+00    0.22246519  -0.091892541
## frstlang   -1.2757448 -3.918124e-01   -0.01285163  -0.007786593
## salary   2901.3078044  4.382253e+04 1940.52763601 244.315688687
## satis       2.4320758  1.391489e+00   -0.01361264  -0.046131531
##                quarter      work_yrs      frstlang        salary
## age      -3.567573e-01  1.355880e+01   0.110508420 -2.918528e+04
## sex      -4.304296e-02 -3.956174e-02  -0.001025475  4.429632e+02
## gmat_tot -5.248543e+00 -3.622220e+01  -1.450507340 -1.708814e+02
## gmat_qpc  1.438364e-01 -1.348408e+01   0.384337219  2.285572e+04
## gmat_vpc -2.478357e+00 -2.456201e+00  -1.275744819  2.901308e+03
## gmat_tpc -1.919905e+00 -8.289778e+00  -0.391812392  4.382253e+04
## s_avg    -3.077677e-01  2.224652e-01  -0.012851630  1.940528e+03
## f_avg    -2.193896e-01 -9.189254e-02  -0.007786593  2.443157e+02
## quarter   1.219128e+00 -5.149773e-01   0.026527418 -8.642229e+03
## work_yrs -5.149773e-01  1.360379e+01  -0.002887522 -1.044263e+04
## frstlang  2.652742e-02 -2.887522e-03   0.072053109  1.016680e+02
## salary   -8.642229e+03 -1.044263e+04 101.668015976  2.825177e+09
## satis     5.788536e-02 -2.204771e-02  -0.028254534  6.436294e+03
##                  satis
## age        -0.23993415
## sex        -0.02150799
## gmat_tot    3.49336140
## gmat_qpc   -0.23453692
## gmat_vpc    2.43207578
## gmat_tpc    1.39148856
## s_avg      -0.01361264
## f_avg      -0.04613153
## quarter     0.05788536
## work_yrs   -0.02204771
## frstlang   -0.02825453
## salary   6436.29447323
## satis       0.59914724
cor(mytable)
##                   age          sex      gmat_tot     gmat_qpc     gmat_vpc
## age       1.000000000 -0.031876273 -1.256220e-01 -0.220590341 -0.006721674
## sex      -0.031876273  1.000000000 -4.351109e-02 -0.167904888  0.099184398
## gmat_tot -0.125622047 -0.043511095  1.000000e+00  0.743099719  0.752906719
## gmat_qpc -0.220590341 -0.167904888  7.430997e-01  1.000000000  0.175497777
## gmat_vpc -0.006721674  0.099184398  7.529067e-01  0.175497777  1.000000000
## gmat_tpc -0.131681932 -0.012849186  8.791496e-01  0.690581939  0.688039929
## s_avg     0.164342257  0.073368077  1.435675e-01  0.019038162  0.190665307
## f_avg    -0.034290725  0.042895288  1.010821e-01  0.130285115  0.033106093
## quarter  -0.076614994 -0.086616877 -8.407099e-02  0.008601267 -0.139400223
## work_yrs  0.871679595 -0.023832548 -1.736909e-01 -0.241384675 -0.041357878
## frstlang  0.097619028 -0.008488358 -9.557089e-02  0.094537575 -0.295162826
## salary   -0.130198680  0.018516965 -5.685962e-05  0.028391635  0.003389965
## satis    -0.073500580 -0.061738773  7.981946e-02 -0.020006117  0.195134711
##             gmat_tpc       s_avg        f_avg      quarter     work_yrs
## age      -0.13168193  0.16434226 -0.034290725 -0.076614994  0.871679595
## sex      -0.01284919  0.07336808  0.042895288 -0.086616877 -0.023832548
## gmat_tot  0.87914961  0.14356746  0.101082103 -0.084070990 -0.173690863
## gmat_qpc  0.69058194  0.01903816  0.130285115  0.008601267 -0.241384675
## gmat_vpc  0.68803993  0.19066531  0.033106093 -0.139400223 -0.041357878
## gmat_tpc  1.00000000  0.18894788  0.109811857 -0.128533421 -0.166139876
## s_avg     0.18894788  1.00000000  0.520554250 -0.735421726  0.159136628
## f_avg     0.10981186  0.52055425  1.000000000 -0.382421186 -0.047951357
## quarter  -0.12853342 -0.73542173 -0.382421186  1.000000000 -0.126454286
## work_yrs -0.16613988  0.15913663 -0.047951357 -0.126454286  1.000000000
## frstlang -0.10789784 -0.12631935 -0.055830525  0.089504320 -0.002916547
## salary    0.06094464  0.09632412  0.008846655 -0.147257809 -0.053266846
## satis     0.13288434 -0.04639953 -0.114704819  0.067729421 -0.007722658
##              frstlang        salary        satis
## age       0.097619028 -1.301987e-01 -0.073500580
## sex      -0.008488358  1.851696e-02 -0.061738773
## gmat_tot -0.095570885 -5.685962e-05  0.079819458
## gmat_qpc  0.094537575  2.839164e-02 -0.020006117
## gmat_vpc -0.295162826  3.389965e-03  0.195134711
## gmat_tpc -0.107897839  6.094464e-02  0.132884339
## s_avg    -0.126319350  9.632412e-02 -0.046399534
## f_avg    -0.055830525  8.846655e-03 -0.114704819
## quarter   0.089504320 -1.472578e-01  0.067729421
## work_yrs -0.002916547 -5.326685e-02 -0.007722658
## frstlang  1.000000000  7.125825e-03 -0.135986251
## salary    0.007125825  1.000000e+00  0.156439455
## satis    -0.135986251  1.564395e-01  1.000000000
corrgram(mytable, order= TRUE, lower.panel = panel.shade, upper.panel=panel.pie, text.panel = panel.txt,main="Corrgram of MBA Starting salaries intercorrelation")

#TASK 2b:

#people who got a job
mytable1 <- subset.data.frame(starting_salaries, (salary!=998 & salary !=0 ))
View(mytable1)
model <- lm(salary ~ . , data= mytable1)
summary(model)
## 
## Call:
## lm(formula = salary ~ ., data = mytable1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -106074  -18770    6309   22085  130167 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  61318.83  102115.00   0.600    0.549    
## age            446.07    2287.54   0.195    0.846    
## sex           8357.64    8021.94   1.042    0.299    
## gmat_tot      -296.81     263.45  -1.127    0.262    
## gmat_qpc       296.57     711.50   0.417    0.678    
## gmat_vpc       -93.41     691.00  -0.135    0.893    
## gmat_tpc       675.03     505.03   1.337    0.184    
## s_avg        10327.60   17641.58   0.585    0.559    
## f_avg        -2134.04    9173.69  -0.233    0.816    
## quarter      -8570.89    5689.33  -1.506    0.134    
## work_yrs      1171.68    2390.24   0.490    0.625    
## frstlang    -15309.00   13461.41  -1.137    0.258    
## satis        20286.55    3169.84   6.400 2.84e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 38670 on 125 degrees of freedom
## Multiple R-squared:  0.3863, Adjusted R-squared:  0.3273 
## F-statistic: 6.556 on 12 and 125 DF,  p-value: 5.51e-09
mytable2<- xtabs(~ sex + satis + work_yrs, data= mytable1)
mytable2
## , , work_yrs = 0
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  1  1  0  0
##   2  0  0  0  0  0  0  0
## 
## , , work_yrs = 1
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  4  1  1
##   2  0  0  0  0  3  0  1
## 
## , , work_yrs = 2
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  4  4 14  6
##   2  0  1  0  0  5  5  5
## 
## , , work_yrs = 3
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  1  0  1  2  5 13  1
##   2  0  0  1  0  2  1  2
## 
## , , work_yrs = 4
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  2  3  4  8  3
##   2  0  0  0  1  1  0  0
## 
## , , work_yrs = 5
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  1  2  3  0
##   2  0  0  0  0  1  1  1
## 
## , , work_yrs = 6
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  2  4  0
##   2  0  0  0  1  1  1  0
## 
## , , work_yrs = 7
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  1  0  2  0  0
##   2  0  0  0  0  0  0  0
## 
## , , work_yrs = 8
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  0  2  1
##   2  0  0  0  0  0  1  0
## 
## , , work_yrs = 9
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  0  1  0
##   2  0  0  0  0  0  0  0
## 
## , , work_yrs = 10
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  0  0  1
##   2  0  0  0  0  0  0  0
## 
## , , work_yrs = 15
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  0  1  0
##   2  0  0  0  0  0  1  0
## 
## , , work_yrs = 16
## 
##    satis
## sex  1  2  3  4  5  6  7
##   1  0  0  0  0  1  0  1
##   2  0  0  0  0  0  0  0
mytable3 <- xtabs(~ sex + satis, data= mytable1)
mytable3
##    satis
## sex  1  2  3  4  5  6  7
##   1  1  0  4 11 25 47 14
##   2  0  1  1  2 13 10  9
chisq.test(mytable3)
## Warning in chisq.test(mytable3): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  mytable3
## X-squared = 9.5421, df = 6, p-value = 0.1453
chisq.test(mytable3)$p.value
## Warning in chisq.test(mytable3): Chi-squared approximation may be incorrect
## [1] 0.1453057
t.test(salary ~ sex, data= mytable1)
## 
##  Welch Two Sample t-test
## 
## data:  salary by sex
## t = -1.2601, df = 72.408, p-value = 0.2117
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -27337.580   6161.152
## sample estimates:
## mean in group 1 mean in group 2 
##        74390.98        84979.19
t.test(work_yrs ~ sex, data= mytable1)
## 
##  Welch Two Sample t-test
## 
## data:  work_yrs by sex
## t = 1.0187, df = 65.372, p-value = 0.3121
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.5052135  1.5575011
## sample estimates:
## mean in group 1 mean in group 2 
##        3.803922        3.277778
fit <- lm(salary ~ age + gmat_qpc + gmat_tot + gmat_tpc + gmat_vpc + s_avg + f_avg + work_yrs , data=mytable1)
summary(fit)
## 
## Call:
## lm(formula = salary ~ age + gmat_qpc + gmat_tot + gmat_tpc + 
##     gmat_vpc + s_avg + f_avg + work_yrs, data = mytable1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -103721  -24776   13153   26311  148502 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 212081.2    98430.6   2.155  0.03305 * 
## age          -2822.5     2341.4  -1.206  0.23021   
## gmat_qpc       642.6      802.7   0.801  0.42489   
## gmat_tot      -595.7      295.1  -2.018  0.04561 * 
## gmat_tpc       779.1      567.1   1.374  0.17188   
## gmat_vpc       898.3      733.7   1.224  0.22303   
## s_avg        35619.0    12239.8   2.910  0.00426 **
## f_avg         -480.2    10399.4  -0.046  0.96324   
## work_yrs      4248.5     2612.4   1.626  0.10633   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 44430 on 129 degrees of freedom
## Multiple R-squared:  0.1638, Adjusted R-squared:  0.1119 
## F-statistic: 3.158 on 8 and 129 DF,  p-value: 0.00268
fitted(fit)
##          5          9         21         26         30         35 
##  80464.687  92556.234 104719.948  95005.546  31593.444  97650.379 
##         36         37         38         39         40         41 
##  68151.049  85259.487  93496.865  61562.579  93492.945  75432.808 
##         42         43         44         45         46         47 
##  90308.874 100357.914  81186.699  99249.699  93098.964  90868.952 
##         48         49         50         51         52         53 
## 102575.671  87872.062  95060.001 114166.574  98205.326  92176.242 
##         54         55         56         57         58         59 
## 105551.115 107859.589  92516.765  87341.391 103781.599 104692.509 
##         60         61         62         63         64         65 
## 122800.922  92310.260  69153.763 109071.933  97600.692  93471.161 
##         66         67         68         69         78         87 
## 102020.206  93515.246 131953.497  78072.091  68937.871  70014.687 
##         91         99        101        105        108        115 
##  41071.224  77936.282  76571.673  95494.961  70968.328  67903.512 
##        116        117        118        119        120        121 
##  80865.997  90762.858  78205.780  92487.613  93938.080  78108.243 
##        122        123        124        125        126        127 
##  98753.423  88935.247  68859.186  84750.840  83443.760  76584.562 
##        128        129        130        131        132        133 
##  80865.997  79309.972  85263.674  73793.506  84243.016 113998.878 
##        134        135        136        137        138        139 
##  76983.787  81610.737  79073.292  91061.408  88703.987  83286.027 
##        145        152        158        161        166        170 
##  61099.089  65571.286  71337.197  60420.603  29816.948  48508.177 
##        179        181        186        187        188        189 
##  93992.144  71898.842  76627.417  64296.780  78879.895  70771.187 
##        190        191        192        193        194        195 
##  81432.579  80733.390  82985.385  69398.364  71615.379  81179.192 
##        196        197        198        199        200        201 
##  73497.418  60019.816  65777.710  63680.506  59384.892  74606.568 
##        202        203        204        205        206        207 
##  77310.618  82684.202  67454.123  76092.671  66987.746  50618.905 
##        208        209        212        214        217        221 
##  82224.900  61588.047  65042.377  65012.833  48547.918  61442.062 
##        223        226        228        231        235        239 
##  62845.469  55881.295  -3771.632  87205.430  51949.184  47119.312 
##        240        245        246        251        252        256 
##  70335.700  51905.088  65710.219  73010.930  43067.744 103077.541 
##        257        258        259        260        261        262 
##  64203.074  75150.670  59998.015  75386.284  63911.527  77807.613 
##        263        264        265        266        267        268 
##  63903.262  53885.011  56333.325  71577.906  57545.856  60036.479 
##        269        270        271        272        273        274 
##  63805.282  46942.933  62213.563  65824.182  67220.802  71497.677
residuals(fit)
##            5            9           21           26           30 
##  -79465.6868  -91557.2343 -103720.9476  -94006.5458  -30594.4445 
##           35           36           37           38           39 
##  -12650.3791   16848.9514     740.5127   -5496.8651   30437.4214 
##           40           41           42           43           44 
##    -492.9446   19567.1922    4691.1257   -5357.9141   14813.3005 
##           45           46           47           48           49 
##   -3249.6995    6901.0357    9131.0484   -2575.6710   17127.9379 
##           50           51           52           53           54 
##    9939.9994   -9166.5744    6794.6740   12823.7580    -551.1151 
##           55           56           57           58           59 
##   -1859.5890   13483.2355   20158.6094    4218.4014    5307.4907 
##           60           61           62           63           64 
##  -10800.9217   22689.7402   45846.2375    8928.0674   22399.3080 
##           65           66           67           68           69 
##   26528.8387   17979.7943   26484.7540   14046.5029   83927.9092 
##           78           87           91           99          101 
##  -67938.8715  -69015.6867  -40072.2240  -76937.2821  -75572.6729 
##          105          108          115          116          117 
##  -94495.9607  -69969.3282   14096.4881   11134.0033    2237.1419 
##          118          119          120          121          122 
##   16794.2196    2512.3866    2061.9204   18391.7569    -753.4230 
##          123          124          125          126          127 
##    9064.7532   29140.8138   14249.1604   16556.2403   23415.4385 
##          128          129          130          131          132 
##   20134.0033   23690.0279   18736.3264   31206.4937   20756.9844 
##          133          134          135          136          137 
##   -8998.8785   30016.2126   30389.2626   35926.7082   23938.5920 
##          138          139          145          152          158 
##   41296.0132   62513.9733  -60100.0892  -64572.2860  -70338.1969 
##          161          166          170          179          181 
##  -59421.6032  -28817.9483  -47509.1770  -92993.1441  -70899.8421 
##          186          187          188          189          190 
##    1628.5827   24203.2204   11120.1052   19228.8127   11567.4211 
##          191          192          193          194          195 
##   14266.6097   14014.6147   27601.6355   26384.6211   16820.8078 
##          196          197          198          199          200 
##   24502.5815   37980.1841   32222.2896   34319.4940   40615.1081 
##          201          202          203          204          205 
##   25393.4322   23689.3823   18415.7978   35045.8775   28907.3292 
##          206          207          208          209          212 
##   39012.2536   56681.0949   25775.1002   50411.9526  -64043.3774 
##          214          217          221          223          226 
##  -64013.8328  -47548.9179  -60443.0623  -61846.4687  -54882.2946 
##          228          231          235          239          240 
##    4770.6318  -86206.4299  -50950.1836  -46120.3123  -69336.7004 
##          245          246          251          252          256 
##  -50906.0879  -64711.2190  -72011.9296  -42068.7441  -39077.5412 
##          257          258          259          260          261 
##   12796.9263    9849.3304   25001.9846   10613.7159   26088.4733 
##          262          263          264          265          266 
##   14192.3874   31096.7382   42114.9893   41666.6753   28422.0942 
##          267          268          269          270          271 
##   42454.1444   40363.5209   37794.7181   57057.0667   42786.4373 
##          272          273          274 
##   49175.8179   59489.1979  148502.3231

Interpretation:

The regression coefficients are significantly different from zero, (p < 0.001) and this indicates that there is an expected decrease/increase in the salary, depending upon several factors, for example, the salary increases 779.1 times when the ‘gmat_tpc’ score is increased by one.

The multiple R-squared (0.991) indicates that the model accounts for 11.1% of the variance in salary.

mytable4 <- subset.data.frame(starting_salaries, (salary!=998 & salary==0 & salary!=999 ))
View(mytable4)
mytable5<- xtabs(~ sex + satis + work_yrs, data= mytable4)
mytable5
## , , work_yrs = 0
## 
##    satis
## sex  4  5  6  7
##   1  0  1  0  0
##   2  0  0  0  0
## 
## , , work_yrs = 1
## 
##    satis
## sex  4  5  6  7
##   1  1  5  4  2
##   2  0  0  0  0
## 
## , , work_yrs = 2
## 
##    satis
## sex  4  5  6  7
##   1  0  3 10  3
##   2  1  1  2  2
## 
## , , work_yrs = 3
## 
##    satis
## sex  4  5  6  7
##   1  0  3  6  0
##   2  2  2  1  0
## 
## , , work_yrs = 4
## 
##    satis
## sex  4  5  6  7
##   1  0  4  4  0
##   2  0  1  0  0
## 
## , , work_yrs = 5
## 
##    satis
## sex  4  5  6  7
##   1  0  6  1  0
##   2  0  2  3  0
## 
## , , work_yrs = 6
## 
##    satis
## sex  4  5  6  7
##   1  0  0  1  1
##   2  0  0  0  0
## 
## , , work_yrs = 7
## 
##    satis
## sex  4  5  6  7
##   1  0  1  2  0
##   2  0  1  1  0
## 
## , , work_yrs = 8
## 
##    satis
## sex  4  5  6  7
##   1  0  1  1  0
##   2  0  0  0  0
## 
## , , work_yrs = 9
## 
##    satis
## sex  4  5  6  7
##   1  0  0  0  0
##   2  0  0  1  0
## 
## , , work_yrs = 10
## 
##    satis
## sex  4  5  6  7
##   1  0  0  0  0
##   2  0  0  0  1
## 
## , , work_yrs = 11
## 
##    satis
## sex  4  5  6  7
##   1  0  0  1  0
##   2  0  0  0  1
## 
## , , work_yrs = 12
## 
##    satis
## sex  4  5  6  7
##   1  0  2  0  0
##   2  0  0  0  0
## 
## , , work_yrs = 13
## 
##    satis
## sex  4  5  6  7
##   1  0  0  0  0
##   2  0  1  0  0
## 
## , , work_yrs = 16
## 
##    satis
## sex  4  5  6  7
##   1  0  1  0  0
##   2  0  0  0  0
## 
## , , work_yrs = 18
## 
##    satis
## sex  4  5  6  7
##   1  0  0  1  0
##   2  0  0  0  0
## 
## , , work_yrs = 22
## 
##    satis
## sex  4  5  6  7
##   1  0  1  1  0
##   2  0  0  0  0
mytable6 <- xtabs(~ sex + satis, data= mytable4)
mytable6
##    satis
## sex  4  5  6  7
##   1  1 28 32  6
##   2  3  8  8  4
chisq.test(mytable4)
## Warning in chisq.test(mytable4): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  mytable4
## X-squared = NaN, df = 1068, p-value = NA
chisq.test(mytable3)$p.value
## Warning in chisq.test(mytable3): Chi-squared approximation may be incorrect
## [1] 0.1453057