library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(dplyr)
library(tidyr)
library(readxl)
nonprofitimpacts <- read_excel("Desktop/R Homework/nonprofitimpacts2.xlsx")
view(nonprofitimpacts)
head(nonprofitimpacts)
## # A tibble: 6 × 11
##   ResponseId         ProgDem PplSrv MajGiftAmt CEOrace_White BChairrace_White
##   <chr>                <dbl>  <dbl>      <dbl>         <dbl>            <dbl>
## 1 R_6hdrzX5DYuu6hVf        0 300000        500             0                0
## 2 FS_10sszir9xkTX9U5       0  50000        200             0                0
## 3 R_72t5uogX3qcLjlq        0  29000        100             0                0
## 4 R_3lrXJzS0AHM2DqX        0  12000        500             0                0
## 5 FS_3itvPD8YLhTOqWH       0   9000         50             0                0
## 6 FS_5xwR3CqoL2qwfwb       0   8200        100             0                0
## # ℹ 5 more variables: PercentDemPOCBoard <dbl>, Northeast <dbl>, Midwest <dbl>,
## #   South <dbl>, West <dbl>
cor(nonprofitimpacts$CEOrace_White, nonprofitimpacts$BChairrace_White, method = "pearson")
## [1] 0.4796578
plot(nonprofitimpacts$CEOrace_White, nonprofitimpacts$BChairrace_White)

model <- lm(nonprofitimpacts$CEOrace_White~nonprofitimpacts$BChairrace_White, data=nonprofitimpacts)
summary(model)
## 
## Call:
## lm(formula = nonprofitimpacts$CEOrace_White ~ nonprofitimpacts$BChairrace_White, 
##     data = nonprofitimpacts)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.94225  0.05775  0.05775  0.05775  0.47320 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        0.52680    0.01323   39.81   <2e-16 ***
## nonprofitimpacts$BChairrace_White  0.41545    0.01486   27.96   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3078 on 2617 degrees of freedom
## Multiple R-squared:  0.2301, Adjusted R-squared:  0.2298 
## F-statistic:   782 on 1 and 2617 DF,  p-value: < 2.2e-16
plot(lm(nonprofitimpacts$CEOrace_White~nonprofitimpacts$BChairrace_White, data=nonprofitimpacts))