ANLY500_Q2.docx - ANLY500 Q2 Khulan Solongozaya...

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

ANLY500 Q2 Khulan Solongozaya library (readr) irisdata <- read.csv ( "iris_exams.csv" ) str (irisdata) ## 'data.frame': 300 obs. of 6 variables: ## $ id : chr "S001" "S002" "S003" "S004" ... ## $ Species : chr "setosa" "setosa" "setosa" "setosa" ... ## $ Sepal.Length: num 4.75 5.07 5.24 5.48 4.9 ... ## $ Sepal.Width : num 3.3 3.68 3.44 3.96 2.81 ... ## $ Petal.Length: num 1.44 1.21 1.59 1.53 1.49 ... ## $ Petal.Width : num 0.235 0.111 0.405 0.272 0.345 ... head (irisdata) ## id Species Sepal.Length Sepal.Width Petal.Length Petal.Width ## 1 S001 setosa 4.746510 3.301532 1.441511 0.2348507 ## 2 S002 setosa 5.072022 3.678133 1.208144 0.1114255 ## 3 S003 setosa 5.241044 3.442049 1.585426 0.4054026 ## 4 S004 setosa 5.475311 3.960215 1.533434 0.2724266 ## 5 S005 setosa 4.900481 2.806450 1.486378 0.3452578 ## 6 S006 setosa 5.580621 3.857734 1.875316 0.3060997 (1) Linear Regression Analysis: Capture a Regression Model with Only Significant Variables. Set the dependent variable to ‘Species’. Even though the variable is categorical and regression is not the proper model to use we will ignore this fact for the purpose of the assignment. irisdata $ Species <- factor (irisdata $ Species, levels = c ( "setosa" , "versicolor" , "virginica" ), labels = c ( 1 , 2 , 3 )) irisdata $ Species <- as.numeric (irisdata $ Species) str (irisdata $ Species) ## num [1:300] 1 1 1 1 1 1 1 1 1 1 ... # Sepal Width is not a significant variable. We will exclude it since we need
# to run the regression model with only significant values. model1 = lm (Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data = irisdata) summary (model1) ## ## Call: ## lm(formula = Species ~ Sepal.Length + Sepal.Width + Petal.Length + ## Petal.Width, data = irisdata) ## ## Residuals: ##

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture