Q3.docx - Q2_final...

This preview shows page 1 - 5 out of 7 pages.

Q2_final 4/15/2020 dat= read.csv ( "~/Downloads/iris_exams.csv" , header= TRUE ) library (car) ## Loading required package: carData library (ggplot2) library (GGally) ## Registered S3 method overwritten by 'GGally': ## method from ## +.gg ggplot2 #Remove inaccurate data dat $ Petal.Width[dat $ Petal.Width < 0 ]= NA #Remove missing data dat= na.omit (dat) dat $ id= NULL #Remove outlier dat_no_cate=dat[ c ( "Sepal.Length" , "Sepal.Width" , "Petal.Length" , "Pe tal.Width" )] mahal = mahalanobis (dat_no_cate, colMeans (dat_no_cate), cov (dat_no_cate)) cutmahal = qchisq ( 1 -.001 , ncol (dat_no_cate)) badmahal = as.numeric (mahal > cutmahal) table (badmahal) ## badmahal ## 0 1 ## 297 2 noout = subset (dat_no_cate, mahal < cutmahal) random = rchisq ( nrow (noout), 7 ) fake = lm (random ~ ., data = noout) fitted = scale (fake $ fitted.values) standardized = rstudent (fake) hist (standardized)
{ qqnorm (standardized) abline ( 0 , 1 )}
{ plot (fitted, standardized) abline ( 0 , 0 ) abline ( v = 0 )}
ggpairs (dat) ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture