[BlindRUG] I can't go on learning R like this!

Amy Albin amyralbin at gmail.com
Tue Mar 8 17:33:05 UTC 2022


Hello All,

I keep trying to learn R but keep running into problems I just can't
figure out how to solve.

Some of the problems are specific to how to make things screen reader friendly.

In other situations, I'm doing exactly what the script says (bootstrap
function) but it doesn't work! I'm being a good student and trying to
logically trouble shoot and type it different ways but it still
doesn't work!

For this entire thing, I've probably spent about 2 hours on it, and I
don't even know how to read the regression coefficients or test for
homosastecity.

It is so discouraging because in my field, we are expected to be able
to do these things! And I am dedicated! And I do put in the hours! But
I still can't figure it out.

I am thinking of getting a tutor at my school, but they probably
wouldn't know how to make things screen reader friendly.

Can someone hear read the files I attached and give me suggestions?

Thanks!

Best,

Amy Albin
Pronouns: she/her/hers
-------------- next part --------------
#---------------------------------------------------------------------------------------------------------
#R Code for Chapter 7 of:
#
#Field, A. P. & Miles, J. N. V. (2012). Discovering Statistics Using R: and Sex and Drugs and Rock 'N' Roll. London Sage
#
#(c) 2011 Andy P. Field & Jeremy N. V. Miles
#-----------------------------------------------------------------------------------------------------------




#----Set the working directory------
setwd("~/Dropbox/Team Field/DSUR/DSUR_2/DSUR2 Data Files/Chapter 07 (Regression)")
setwd("~/Documents/Academic/Data/DSU_R/Chapter 07 (Regression)")
imageDirectory<-"~/Documents/Academic/Books/Discovering Statistics/DSU R/DSU R I/DSUR I Images"

setwd("~/Public/Academic/Data/DSU_R/Chapter 07 (Regression)")
imageDirectory<-"~/Public/Academic/Books/Discovering Statistics/DSU R/DSU R I/DSUR I Images"



#----Install Packages-----
install.packages("QuantPsyc")
install.packages("car")


#------And then load these packages, along with the boot package.-----
library(QuantPsyc)
library(car)
library(boot)
library(Rcmdr)


#Jane superbrain box
pubs<-read.delim("pubs.dat", header = TRUE)
pubReg <- lm(mortality ~ pubs, data = pubs)
summary(pubReg)
resid(pubReg)
rstandard(pubReg)
rstudent(pubReg)

PearsonResidual <- (resid(pubReg)-mean(resid(pubReg)))/sd(resid(pubReg))

#----run the command to access the album1 data-----
album1<-read.delim("Album Sales 1.dat", header = TRUE)

#----run the simple linear regression model---
albumSales.1 <- lm(sales ~ adverts, data = album1)
summary(albumSales.1)
sqrt(0.3346)

#----access the album2 data----
album2<-read.delim("Album Sales 2.dat", header = TRUE)


#---Run the multiple regression model----
albumSales.2<-lm(sales ~ adverts, data = album2)
albumSales.3<-lm(sales ~ adverts + airplay + attract, data = album2)
summary(albumSales.2)
summary(albumSales.3)

#---We can obtain standardized parameter estimates with the lm.beta() function---
lm.beta(albumSales.3)
#---Confidence intervals are obtained with the confint() function----
confint(albumSales.3)

#----To compare the R2 in two models, use the ANOVA command---
anova(albumSales.2, albumSales.3)


#----Obtain casewise diagnostics and add them to the original data file.---

album2$residuals<-resid(albumSales.3)
album2$standardized.residuals <- rstandard(albumSales.3)
album2$studentized.residuals <- rstudent(albumSales.3)
album2$cooks.distance<-cooks.distance(albumSales.3)
album2$dfbeta <- dfbeta(albumSales.3)
album2$dffit <- dffits(albumSales.3)
album2$leverage <- hatvalues(albumSales.3)
album2$covariance.ratios <- covratio(albumSales.3)

#Save file
write.table(album2, "Album Sales With Diagnostics.dat", sep = "\t", row.names = FALSE)
#look at the data (and round the values)
round(album2, digits = 3)


#----List of standardized residuals greater than 2--------------
album2$standardized.residuals>2| album2$standardized.residuals < -2

#---Create a variable called large.residual, which is TRUE (or 1) if the residual is greater than 2, or less than -2.----------
album2$large.residual <- album2$standardized.residuals > 2 | album2$standardized.residuals < -2

#---Count the number of large residuals-------------
sum(album2$large.residual)


#---Display the value of sales, airplay, attract, adverts, and the standardized residual, for those cases which have a residual greater than 2 or less than -2.-------------
album2[album2$large.residual,c("sales", "airplay", "attract", "adverts", "standardized.residuals")]

#-----Cook's distance, leverage and covariance ratio for cases with large residuals.---------
album2[album2$large.residual , c("cooks.distance", "leverage", "covariance.ratios")]


#----The Durbin-Watson test is obtained with either dwt() or durbinWatsonTest()---
durbinWatsonTest(albumSales.3)
dwt(albumSales.3)

#----Obtaining the VIF---
vif(albumSales.3)

#----The tolerance is 1/VIF---
1/vif(albumSales.3)

#----The mean VIF---
mean(vif(albumSales.3))


#---Histogram of studentized residuals---

hist(album2$studentized.residuals)
hist(rstudent(albumSales.3))

#--Plot of residuals against fitted (predicted) values, with a flat line at the mean--
plot(albumSales.3$fitted.values,rstandard(albumSales.3))
abline(0, 0)

#same as above
plot(albumSales.3)

#Publication quality graphs

album2$fitted <- albumSales.3$fitted.values

histogram<-ggplot(album2, aes(studentized.residuals)) + opts(legend.position = "none") + geom_histogram(aes(y=..density..), colour="black", fill="white") + labs(x = "Studentized Residual", y = "Density")
histogram + stat_function(fun = dnorm, args = list(mean = mean(album2$studentized.residuals, na.rm = TRUE), sd = sd(album2$studentized.residuals, na.rm = TRUE)), colour = "red", size = 1)
ggsave(file = paste(imageDirectory,"07 album sales ggplot Hist.png",sep="/"))

scatter <- ggplot(album2, aes(fitted, studentized.residuals))
scatter + geom_point() + geom_smooth(method = "lm", colour = "Red")+ labs(x = "Fitted Values", y = "Studentized Residual") 
ggsave(file=paste(imageDirectory,"07 Album sales ggplot scatter.png",sep="/"))

qqplot.resid <- qplot(sample = album2$studentized.residuals, stat="qq") + labs(x = "Theoretical Values", y = "Observed Values") 
qqplot.resid
ggsave(file=paste(imageDirectory,"07 Album sales ggplot QQ.png",sep="/"))


#---R tends to give values to too many decimal places, you can usefully round these values to 2 decimals.
round(rstandard(albumSales.3), 2)



##------Bootstrapping------
#---Write a bootstrap function.
object<-boot(data,function,replications)


bootReg<-function(formula, data, i)
{
	d <- data[i,]
	fit <- lm(formula, data = d)
	return(coef(fit))
	}

#----bootstrapping our regression model, with 2000 replications---
bootResults<-boot(statistic = bootReg, formula = sales ~ adverts + airplay + attract, data = album2, R = 2000,)

#---We can then obtaine the bootstrap confidence intervals for the intercept:---
boot.ci(bootResults, type = "bca", index = 1)

#---And the three slope estimates---
boot.ci(bootResults, type = "bca", index = 2)
boot.ci(bootResults, type = "bca", index = 3)
boot.ci(bootResults, type = "bca", index = 4)

#-----Read in data for Glastonbury Festival Regression----
gfr<-read.delim(file="GlastonburyFestivalRegression.dat", header = TRUE)

#Print the first 10 cases of the dataframe
head(gfr, n = 10)
#set contrasts quickly
contrasts(gfr$music)<-contr.treatment(4, base = 4)
#set contrasts with helpful names

crusty_v_NMA<-c(1, 0, 0, 0)
indie_v_NMA<-c(0, 1, 0, 0)
metal_v_NMA<-c(0, 0, 1, 0)
contrasts(gfr$music)<-cbind(crusty_v_NMA, indie_v_NMA, metal_v_NMA)



#----Exactly the same results can be obtained with------
glastonburyModel<-lm(change ~ music, data = gfr) 
summary(glastonburyModel)


#---To produce group means of each of the four groups-----
round(tapply(gfr$change, gfr$music, mean, na.rm=TRUE), 3)


#********************Labcoat Leni*******************************

#Load data & set gender to be a factor

PersonalityData<-read.delim("Chamorro-Premuzic.dat", header = TRUE)
PersonalityData$Gender<-factor(PersonalityData$Gender, levels = c(0:1), labels = c("Female", "Male"))

#Create dataframes containing variables for each analysis (need to do this because of missing values). Drop variables not in analysis
dropVars<-names(PersonalityData) %in% c("lecturerE","lecturerO", "lecturerA", "lecturerC")
neuroticLecturer<-PersonalityData[!dropVars]

dropVars<-names(PersonalityData) %in% c("lecturerN","lecturerO", "lecturerA", "lecturerC")
extroLecturer<-PersonalityData[!dropVars]

dropVars<-names(PersonalityData) %in% c("lecturerE","lecturerN", "lecturerA", "lecturerC")
openLecturer<-PersonalityData[!dropVars]

dropVars<-names(PersonalityData) %in% c("lecturerE","lecturerO", "lecturerN", "lecturerC")
agreeLecturer<-PersonalityData[!dropVars]

dropVars<-names(PersonalityData) %in% c("lecturerE","lecturerO", "lecturerA", "lecturerN")
concLecturer<-PersonalityData[!dropVars]

#Delete cases with any missing values on any variable
neuroticLecturer <-neuroticLecturer[complete.cases(neuroticLecturer),]
extroLecturer <-extroLecturer[complete.cases(extroLecturer),]
openLecturer <-openLecturer[complete.cases(openLecturer),]
agreeLecturer <-agreeLecturer[complete.cases(agreeLecturer),]
concLecturer <-concLecturer[complete.cases(concLecturer),]

#-----Neurotic Lecturer-----------
#-----Create two models-------
LecturerN.1<- lm(lecturerN ~ Age + Gender, data= neuroticLecturer)
LecturerN.2 <- lm(lecturerN ~ Age + Gender + studentN + studentE + studentO + studentA + studentC, data= neuroticLecturer)
#-----Run an anova to compare the two models------
anova(LecturerN.1, LecturerN.2)
#-----To obtain output----
summary(LecturerN.1)
summary(LecturerN.2)
#----Statistics------
vif(LecturerN.2)
dwt(LecturerN.2)

#---Histogram-----
hist(rstudent(LecturerN.2))

#-----Confidence intervals-----
confint(LecturerN.2)

##-----obtain the standardized beta estimates:------
install.packages("QuantPsyc")
Library(QuantPsyc)
lm.beta(LecturerN.1)
lm.beta(LecturerN.2)
#-----Extroverted Lecturer-----------
#----Create two models-------
LecturerE.1 <- lm(lecturerE ~ Age + Gender, data=extroLecturer)
LecturerE.2 <- lm(lecturerE ~ Age + Gender + studentN + studentE + studentO + studentA + studentC, data= extroLecturer)
#-----Run an anova to compare the two models------
anova(LecturerE.1, LecturerE.2)
#-----To obtain output----
summary(LecturerE.1)
summary(LecturerE.2)
#----Statistics------
vif(LecturerE.2)
dwt(LecturerE.2)

#---Histogram-----
hist(rstudent(LecturerE.2))

#-----Confidence intervals-----
confint(LecturerE.2)

##-----obtain the standardized beta estimates:------
install.packages("QuantPsyc")
Library(QuantPsyc)
lm.beta(LecturerE.1)
lm.beta(LecturerE.2)
#-----Openness to Experience Lecturer-----------
#----Create two models-------
LecturerO.1 <- lm(lecturerO ~ Age + Gender, data=openLecturer)
LecturerO.2 <- lm(lecturerO ~ Age + Gender + studentN + studentE + studentO + studentA + studentC, data=openLecturer)
#-----Run an anova to compare the two models------
anova(LecturerO.1, LecturerO.2)
#-----To obtain output----
summary(LecturerO.1)
summary(LecturerO.2)
#----Statistics------
vif(LecturerO.2)
dwt(LecturerO.2)

#---Histogram-----
hist(rstudent(LecturerO.2))

#-----Confidence intervals-----
confint(LecturerO.2)

##-----obtain the standardized beta estimates:------

lm.beta(LecturerO.1)
lm.beta(LecturerO.2)
#-----Agreeableness Lecturer-----------
#----Create two models-------
LecturerA.1 <- lm(lecturerA ~ Age + Gender, data=agreeLecturer)
LecturerA.2 <- lm(lecturerA ~ Age + Gender + studentN + studentE + studentO + studentA + studentC,data=agreeLecturer)
#-----Run an anova to compare the two models------
anova(LecturerA.1, LecturerA.2)
#-----To obtain output----
summary(LecturerA.1)
summary(LecturerA.2)
#----Statistics------
vif(LecturerA.2)
dwt(LecturerA.2)

#---Histogram-----
hist(rstudent(LecturerA.2))

#-----Confidence intervals-----
confint(LecturerA.2)

##-----obtain the standardized beta estimates:------

lm.beta(LecturerA.1)
lm.beta(LecturerA.2)
#-----Concientious Lecturer-----------

#----Create two models-------
LecturerC.1 <- lm(lecturerC ~ Age + Gender, data=concLecturer)
LecturerC.2 <- lm(lecturerC ~ Age + Gender + studentN + studentE + studentO + studentA + studentC,data=concLecturer)
#-----Run an anova to compare the two models------
anova(LecturerC.1, LecturerC.2)
#-----To obtain output----
summary(LecturerC.1)
summary(LecturerC.2)
#----Statistics------
vif(LecturerC.2)
dwt(LecturerC.2)

#---Histogram-----
hist(rstudent(LecturerC.2))

#-----Confidence intervals-----
confint(LecturerC.2)

##-----obtain the standardized beta estimates:------

lm.beta(LecturerC.1)
lm.beta(LecturerC.2)

#*********************Smart Alex********************

#---Task 1------
#load in the pubs.dat data:

pubs<-read.delim("pubs.dat", header = TRUE)

#create a regression model to predict mortality from number of pubs:

pubsReg <-lm(mortality ~ pubs, data = pubs)

#obtain output of the regression:

summary(pubsReg)

#--Bootstrap the regression parameters:
#first execute the bootreg() function from the book chapter.

#We can then use the function to obtain the bootstrap samples:
bootResults<-boot(statistic = bootReg, formula = mortality ~ pubs, data = pubs, R = 2000)

#Obtain the bootstrap confidence intervals for the intercept and slope:
boot.ci(bootResults, type = "bca", index = 1)

boot.ci(bootResults, type = "bca", index = 2)

#---Task 2------

#load in the Supermodel.dat data--

Supermodel<-read.delim("Supermodel.dat", header = TRUE)

#----create a regression model to predict salery from Age, number of years being a supermodel and beauty-----
Supermodel.1 <- lm(salary~age + beauty + years, data= Supermodel)

#--obtain output of the regression---

summary(Supermodel.1)

##-----obtain the standardized beta estimates:------

lm.beta(Supermodel.1)

##---is the model valid?----
vif(Supermodel.1)
1/vif(Supermodel.1)
dwt(Supermodel.1)
resid(Supermodel.1)
rstandard(Supermodel.1)

#----Histogram-----
hist(rstandard(Supermodel.1))

##---Plot of the standardized residuals----- 
plot(Supermodel.1$fitted.values,rstandard(Supermodel.1))

#---It also helps to add a horizontal line at the mean--
abline(0,0)

#To obtain some other plots, we can use the plot() function:

plot(Supermodel.1)
#----Obtain casewise diagnostics and add them to the original data 
Supermodel$cooks.distance<-cooks.distance(Supermodel.1)
Supermodel$residuals<-resid(Supermodel.1)
Supermodel$standardized.residuals <- rstandard(Supermodel.1)
Supermodel$studentized.residuals <- rstudent(Supermodel.1)
Supermodel$dfbeta <- dfbeta(Supermodel.1)
Supermodel$dffit <- dffits(Supermodel.1)
Supermodel$leverage <- hatvalues(Supermodel.1)
Supermodel$covariance.ratios <- covratio(Supermodel.1)

#----List of standardized residuals greater than 2--------------
Supermodel$standardized.residuals>2| Supermodel$standardized.residuals < -2

#---Create a variable called large.residual, which is TRUE (or 1) if the residual is greater than 2, or less than -2.----------
Supermodel$large.residual <- Supermodel$standardized.residuals > 2| Supermodel$standardized.residuals < -2

#---Count the number of large residuals-------------
sum(Supermodel$large.residual)

#-----If we want to display only some of the variables we can use:----
Supermodel[,c("salary", "age", "beauty", "years", "standardized.residuals")]

#---Display the value of salary, age, beauty, years, and the standardized residual, for those cases which have a residual greater than 2 or less than -2.-------------

Supermodel[Supermodel$large.residual,c("salary", "age", "beauty", "years", "standardized.residuals")]

#------Task 3-------------------------

#-----Read in data for Glastonbury Festival Regression----

gfr<-read.delim("GlastonburyFestivalRegression.dat", header=TRUE)

#---Create three dummy variables. Make sure you don't do this if there are missing data.---
gfr$crusty<-gfr$music=="Crusty"
gfr$metaller<-gfr$music=="Metaller"
gfr$indie.kid<-gfr$music=="Indie Kid"

#---Create a regression model---------

gfr.1 <- lm(gfr$change ~ gfr$crusty + gfr$metaller + gfr$indie.kid, data=gfr)
summary(gfr.1)

##---is the model valid?----
vif(gfr.1)
1/vif(gfr.1)

# The Durbin–Watson statistic: 

dwt(gfr.1)

#----Histogram-----
hist(rstandard(gfr.1))

##---Plot of the standardized residuals----- 
plot(gfr.1$fitted.values,rstandard(gfr.1))

#---It also helps to add a horizontal line at the mean--
abline(0,0)

#To obtain some other plots, we can use the plot() function:
plot(gfr.1)

#----Obtain casewise diagnostics and add them to the original data 
gfr$cooks.distance<-cooks.distance(gfr.1)
gfr$residuals<-resid(gfr.1)
gfr$standardized.residuals<-rstandard(gfr.1)
gfr$studentized.residuals<-rstudent(gfr.1)
gfr$dfbeta<-dfbeta(gfr.1)
gfr$dffit<-dffits(gfr.1)
gfr$leverage<-hatvalues(gfr.1)
gfr$covariance.ratios<-covratio(gfr.1)

#----List of standardized residuals greater than 2--------------
gfr$standardized.residuals>2| gfr$standardized.residuals < -2

#---Create a variable called large.residual, which is TRUE (or 1) if the residual is greater than 2, or less than -2.----------
gfr$large.residual <- gfr$standardized.residuals > 2| gfr$standardized.residuals < -2

#---Count the number of large residuals-------------
sum(gfr$large.residual)

#-----If we want to display only some of the variables we can use:----
gfr[,c("change", "crusty", "metaller", "indie.kid", "standardized.residuals")]

#---Display the value of change, crusty, metaller, indie.kid, and the standardized residual, for those cases which have a residual greater than 2 or less than -2.-------------

gfr[gfr$large.residual,c("change", "crusty", "metaller", "indie.kid", "standardized.residuals")]

#------Task 4----------

#-----Read in data for Child Aggression----

ChildAggression<-read.delim("ChildAggression.dat", header = TRUE)

#---Conduct the analysis hierarhically entering parenting style and sibling aggression in the first step-------

ChildAggression.1<-lm(Aggression ~ Sibling_Aggression + Parenting_Style, data = ChildAggression)

#------And the remaining variables in a second step-----

ChildAggression.2<-lm(Aggression ~ Sibling_Aggression+Parenting_Style+ Diet + Computer_Games + Television, data=ChildAggression)

#----View the output of the two regressions---

summary(ChildAggression.1)
summary(ChildAggression.2)

#----To compare the R2 in two models, use the ANOVA command---

anova(ChildAggression.1, ChildAggression.2)

#---VIF------

vif(ChildAggression.1)
1/vif(ChildAggression.1)

vif(ChildAggression.2)
1/vif(ChildAggression.2)


#----The Durbin-Watson test is obtained with either dwt() or durbinWatsonTest()---

durbinWatsonTest(ChildAggression.1)
dwt(ChildAggression.2)

#---Histogram of standardized residuals---

hist(rstandard(ChildAggression.2))

#--Plot of residuals against fitted (predicted) values, with a flat line at the mean--
plot(ChildAggression.2$fitted.values,rstandard(ChildAggression.2))
abline(0, 0)

#---We can obtain standardized parameter estimates with the lm.beta() function---

lm.beta(ChildAggression.1)
lm.beta(ChildAggression.2)

#---Confidence intervals are obtained with the confint() function----
confint(ChildAggression.2)

#----You can round them to make life easier----
round(confint(ChildAggression.2), 2)

#To obtain some other plots, we can use the plot() function:

plot(ChildAggression.2)

#----Obtain casewise diagnostics and add them to the original data 
ChildAggression$cooks.distance<-cooks.distance(ChildAggression.2)
ChildAggression$residuals<-resid(ChildAggression.2)
ChildAggression$standardized.residuals <- rstandard(ChildAggression.2)
ChildAggression$studentized.residuals <- rstudent(ChildAggression.2)
ChildAggression$dfbeta <- dfbeta(ChildAggression.2)
ChildAggression$dffit <- dffits(ChildAggression.2)
ChildAggression$leverage <- hatvalues(ChildAggression.2)
ChildAggression$covariance.ratios <- covratio(ChildAggression.2)

#----List of standardized residuals greater than 2--------------
ChildAggression$standardized.residuals>2| ChildAggression$standardized.residuals < -2

#---Create a variable called large.residual, which is TRUE (or 1) if the residual is greater than 2, or less than -2.----------
ChildAggression$large.residual <- ChildAggression$standardized.residuals > 2| ChildAggression$standardized.residuals < -2

#---Count the number of large residuals-------------
sum(ChildAggression$large.residual)

#-----If we want to display only some of the variables we can use:----
ChildAggression[,c("Aggression", "Sibling_Aggression","Parenting_Style","Diet","Computer_Games", "Television", "standardized.residuals")]

#---Display the value of Aggression, Parenting_Style, Diet, Computer_Games and Television and the standardized residual, for those cases which have a residual greater than 2 or less than -2.-------------

ChildAggression[ChildAggression$large.residual,c("Aggression", "Sibling_Aggression","Parenting_Style","Diet","Computer_Games", "Television", "standardized.residuals")]

-------------- next part --------------

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BrailleR)
The BrailleR.View option has been set to TRUE.
Consult the help page for GoSighted() to see how settings can be altered.
You may wish to use the GetGoing() function as a quick way of getting started.

Attaching package: 'BrailleR'

The following objects are masked from 'package:graphics':

    boxplot, hist

The following object is masked from 'package:utils':

    history

The following objects are masked from 'package:base':

    grep, gsub

> txtOut()
Please enter a filename and press <enter>.
Pressing <enter> alone will generate a default  filename
based on the current date and time.

1: Zinkle9
2:
Output being copied to text file,
use txtStop() to end.

txt> #Chapter 7 Regression
txt> library(boot); library(car); library(QuantPsyc)
Loading required package: carData

Attaching package: 'car'

The following object is masked from 'package:boot':

    logit

Warning message:
package 'car' was built under R version 4.0.5
Loading required package: MASS

Attaching package: 'QuantPsyc'

The following object is masked from 'package:base':

    norm

Warning message:
package 'QuantPsyc' was built under R version 4.0.5
txt> album1<-read.delim("Album Sales 1.dat", header = TRUE)
txt> albumSales.1 <- lm(sales ~ adverts, data = album1, na.action = na.exclude)
txt> AlbumSalesModel1 <- summary(albumSales.1)
txt> write.csv(AlbumSalesModel1, "AlbumSalesModel1.csv")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
  cannot coerce class '"summary.lm"' to a data.frame
txt> AlbumSalesModel1

Call:
lm(formula = sales ~ adverts, data = album1, na.action = na.exclude)

Residuals:
     Min       1Q   Median       3Q      Max
-152.949  -43.796   -0.393   37.040  211.866

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.341e+02  7.537e+00  17.799   <2e-16 ***
adverts     9.612e-02  9.632e-03   9.979   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 65.99 on 198 degrees of freedom
Multiple R-squared:  0.3346,    Adjusted R-squared:  0.3313
F-statistic: 99.59 on 1 and 198 DF,  p-value: < 2.2e-16

txt> #How do we get this into a screen reader friendly format?
txt> write.csv(albumSales.1, "albumSales.1.csv")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
  cannot coerce class '"lm"' to a data.frame
txt> AlbumSalesModel1 <- as.data.frame(AlbumSalesModel1)
Error in as.data.frame.default(AlbumSalesModel1) :
  cannot coerce class '"summary.lm"' to a data.frame
txt> #Assistance: How can I make this summary screen reader friendly?
txt> sqrt(0.3346)
[1] 0.5784462
txt> sqrt(0.3313)
[1] 0.5755867
txt> sqrt(0.3346)
[1] 0.5784462
txt> #Assistance: b0 (y-intercept) is supposed to be 134.1. Why do I get 1.341$
txt>
txt> album2<-read.delim("Album Sales 2.dat", header = TRUE)
txt> albumSales.2 <- lm(sales ~ adverts, data = album2)
txt> albumSales.3 <- lm(sales ~ adverts + airplay + attract, data = album2)
txt> AlbumModel2 <- summary(albumSales.2)
txt> AlbumModel3 <- summary(albumSales.3)
txt> class(AlbumModel2)
[1] "summary.lm"
txt> #Assistance: Again, how do we get these into screen reader friendly table$
txt> AlbumModel2

Call:
lm(formula = sales ~ adverts, data = album2)

Residuals:
     Min       1Q   Median       3Q      Max
-152.949  -43.796   -0.393   37.040  211.866

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.341e+02  7.537e+00  17.799   <2e-16 ***
adverts     9.612e-02  9.632e-03   9.979   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 65.99 on 198 degrees of freedom
Multiple R-squared:  0.3346,    Adjusted R-squared:  0.3313
F-statistic: 99.59 on 1 and 198 DF,  p-value: < 2.2e-16

txt> AlbumModel3

Call:
lm(formula = sales ~ adverts + airplay + attract, data = album2)

Residuals:
     Min       1Q   Median       3Q      Max
-121.324  -28.336   -0.451   28.967  144.132

Coefficients:
              Estimate Std. Error t value Pr(>|t|)
(Intercept) -26.612958  17.350001  -1.534    0.127
adverts       0.084885   0.006923  12.261  < 2e-16 ***
airplay       3.367425   0.277771  12.123  < 2e-16 ***
attract      11.086335   2.437849   4.548 9.49e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 47.09 on 196 degrees of freedom
Multiple R-squared:  0.6647,    Adjusted R-squared:  0.6595
F-statistic: 129.5 on 3 and 196 DF,  p-value: < 2.2e-16

txt> Compare2&3 <- anova(albumSales.2, albumSales.3)
Error in Compare2 & 3 <- anova(albumSales.2, albumSales.3) :
  object 'Compare2' not found
txt> Compare2.3 <- anova(albumSales.2, albumSales.3)
txt> Compare2.3
Analysis of Variance Table

Model 1: sales ~ adverts
Model 2: sales ~ adverts + airplay + attract
  Res.Df    RSS Df Sum of Sq      F    Pr(>F)
1    198 862264
2    196 434575  2    427690 96.447 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
txt> class(Compare2.3)
[1] "anova"      "data.frame"
txt> write.csv(Compare2.3, "Compare2.3.csv")
txt> #Assistance: In the comparison, Pr(>F) is supposed to be 2.2e-16. Why am $
txt>
txt> album2$residuals<-resid(albumSales.3)
txt> album2$standardized.residuals<- rstandard(albumSales.3)
txt> album2$cooks.distance<-cooks.distance(albumSales.3)
txt> album2$dffit<-dffits(albumSales.3)
txt> album2$leverage<-hatvalues(albumSales.3)
txt> album2$covariance.ratios<-covratio(albumSales.3)
txt> write.csv(album2, "album2.csv", row.names = FALSE)
txt>
txt> album2$large. residual <- album2$standardized. residuals > 2 | album2$sta$
Error: unexpected symbol in "album2$large. residual"
txt> #I copied this command straight from the book!
txt> album2$large.residual <- album2$standardized.residuals > 2 | album2$stand$
txt> sum(album2$large.residual)
[1] 12
txt> length(album2)
[1] 11
txt> rows(album2)
Error in rows(album2) : could not find function "rows"
txt> nrow(album2)
[1] 200
txt> 200*0.95
[1] 190
txt> special12 <- album2[album2$large.residual, c("sales", "airplay", "attract$
txt> write.csv(special12, "special12.csv")
txt> diagnostic12 <- album2[album2$large.residual, c("cooks.distance", "levera$
Error in `[.data.frame`(album2, album2$large.residual, c("cooks.distance",  :
  undefined columns selected
txt> album2[album2$large.residual, c("cooks.distance", "leverage", "covariance$
Error in `[.data.frame`(album2, album2$large.residual, c("cooks.distance",  :
  undefined columns selected
txt> diagnostic12 <- album2[album2$large.residual, c("cooks.distance", "levera$
txt> write.csv(diagnostic12, "diagnostic12.csv")
txt> cor_album2 <- cor(album2)
txt> write.csv(cor_album2, "cor_album2.csv", row.Names = FALSE)
Error in write.table(cor_album2, "cor_album2.csv", row.Names = FALSE,  :
  unused argument (row.Names = FALSE)
txt> write.csv(cor_album2, "cor_album2.csv", row.names = FALSE)
txt>
txt> 0.02*6+0.005
[1] 0.125
txt> 5/200
[1] 0.025
txt> 0.025*2
[1] 0.05
txt> 0.025*3
[1] 0.075
txt> #Testing for Independence
txt> dwt(albumSales.3)
 lag Autocorrelation D-W Statistic p-value
   1       0.0026951      1.949819   0.744
 Alternative hypothesis: rho != 0
txt> albumIndependence <- dwt(albumSales.3)
txt> class(albumIndependence)
[1] "durbinWatsonTest"
txt> albumIndependence <- as.data.frame(albumIndependence)
Error in as.data.frame.default(albumIndependence) :
  cannot coerce class '"durbinWatsonTest"' to a data.frame
txt> #Assistance: How to make this screen reader friendly?
txt> albumIndependence
 lag Autocorrelation D-W Statistic p-value
   1       0.0026951      1.949819    0.75
 Alternative hypothesis: rho != 0
txt> vif(albumSales.3)
 adverts  airplay  attract
1.014593 1.042504 1.038455
txt> 1/vif(albumSales.3)
  adverts   airplay   attract
0.9856172 0.9592287 0.9629695
txt> mean(vif(albumSales.3))
[1] 1.03185
txt> Graph <- plot(albumSales3)
Error in plot(albumSales3) : object 'albumSales3' not found
txt>


#Assistance: When I had to restart my computer and reload the data, I went to do the graph. I did plot(album.Sales3)
#It took me to an R graphics page, and then when I went back to the terminal it became inaccessible and would not let me type or edit commands so I had to restart R. What should I do?


#Also how do we make these graphs screen reader accessible to assess for homoscedasticity?



R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> plot(X)
Error in plot(X) : object 'X' not found
> #---Write a bootstrap function.
> object<-boot(data,function,replications)
Error: unexpected ',' in "object<-boot(data,function,"
>
>
> bootReg<-function(formula, data, i)
+
+
+ stop
> object<-boot(data,function,replications)
Error: unexpected ',' in "object<-boot(data,function,"
> #Assistance: Why isn't this working? I'm copying directly from the script in$
>






R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> plot(X)
Error in plot(X) : object 'X' not found
> #---Write a bootstrap function.
> object<-boot(data,function,replications)
Error: unexpected ',' in "object<-boot(data,function,"
>
>
> bootReg<-function(formula, data, i)
+
+
+ stop
> object<-boot(data,function,replications)
Error: unexpected ',' in "object<-boot(data,function,"
> #Assistance: Why isn't this working? I'm copying directly from the script in$
> object<-boot(data function replications)
Error: unexpected 'function' in "object<-boot(data function"
> #last ditch
> library(Rcmdr)
Error in library(Rcmdr) : there is no package called 'Rcmdr'
> library(boot)
> library(QuantPsyc)
Loading required package: MASS

Attaching package: 'QuantPsyc'

The following object is masked from 'package:base':

    norm

Warning message:
package 'QuantPsyc' was built under R version 4.0.5
>
> library(car)
Loading required package: carData

Attaching package: 'car'

The following object is masked from 'package:boot':

    logit

Warning message:
package 'car' was built under R version 4.0.5
>
> chooseCRANmirror(ind=1)
>
> install.packages("Rcmdr")
Installing package into 'C:/Users/Amy Albin/Documents/R/win-library/4.0'
(as 'lib' is unspecified)
also installing the dependencies 'zoo', 'mitools', 'sandwich', 'readstata13', 'survey', 'estimability', 'insight', 'RcmdrMisc', 'effects', 'tcltk2', 'relimp'

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/zoo_1.8-9.zip'
Content type 'application/zip' length 1038711 bytes (1014 KB)
downloaded 1014 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/mitools_2.4.zip'
Content type 'application/zip' length 298533 bytes (291 KB)
downloaded 291 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/sandwich_3.0-1.zip'
Content type 'application/zip' length 1488809 bytes (1.4 MB)
downloaded 1.4 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/readstata13_0.10.0.zip'
Content type 'application/zip' length 1011929 bytes (988 KB)
downloaded 988 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/survey_4.1-1.zip'
Content type 'application/zip' length 2728165 bytes (2.6 MB)
downloaded 2.6 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/estimability_1.3.zip'
Content type 'application/zip' length 38901 bytes (37 KB)
downloaded 37 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/insight_0.16.0.zip'
Content type 'application/zip' length 1799813 bytes (1.7 MB)
downloaded 1.7 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/RcmdrMisc_2.7-2.zip'
Content type 'application/zip' length 214447 bytes (209 KB)
downloaded 209 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/effects_4.2-1.zip'
Content type 'application/zip' length 2509617 bytes (2.4 MB)
downloaded 2.4 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/tcltk2_1.2-11.zip'
Content type 'application/zip' length 1171841 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/relimp_1.0-5.zip'
Content type 'application/zip' length 77831 bytes (76 KB)
downloaded 76 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/Rcmdr_2.7-2.zip'
Content type 'application/zip' length 5320196 bytes (5.1 MB)
downloaded 5.1 MB

package 'zoo' successfully unpacked and MD5 sums checked
package 'mitools' successfully unpacked and MD5 sums checked
package 'sandwich' successfully unpacked and MD5 sums checked
package 'readstata13' successfully unpacked and MD5 sums checked
package 'survey' successfully unpacked and MD5 sums checked
package 'estimability' successfully unpacked and MD5 sums checked
package 'insight' successfully unpacked and MD5 sums checked
package 'RcmdrMisc' successfully unpacked and MD5 sums checked
package 'effects' successfully unpacked and MD5 sums checked
package 'tcltk2' successfully unpacked and MD5 sums checked
package 'relimp' successfully unpacked and MD5 sums checked
package 'Rcmdr' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\Amy Albin\AppData\Local\Temp\RtmpGiUQcd\downloaded_packages
> library(Rcmdr)
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: sandwich
Loading required package: effects
lattice theme set by effectsTheme()
See ?effectsTheme for details.
also installing the dependencies 'arm', 'mi', 'TH.data'

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/arm_1.12-2.zip'
Content type 'application/zip' length 414894 bytes (405 KB)
downloaded 405 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/mi_1.0.zip'
Content type 'application/zip' length 1964197 bytes (1.9 MB)
downloaded 1.9 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/TH.data_1.1-0.zip'
Content type 'application/zip' length 8807470 bytes (8.4 MB)
downloaded 8.4 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/sem_3.1-13.zip'
Content type 'application/zip' length 1301050 bytes (1.2 MB)
downloaded 1.2 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/rgl_0.108.3.zip'
Content type 'application/zip' length 4560689 bytes (4.3 MB)
downloaded 4.3 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/multcomp_1.4-18.zip'
Content type 'application/zip' length 735174 bytes (717 KB)
downloaded 717 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/lmtest_0.9-39.zip'
Content type 'application/zip' length 414600 bytes (404 KB)
downloaded 404 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/leaps_3.1.zip'
Content type 'application/zip' length 103006 bytes (100 KB)
downloaded 100 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/aplpack_1.3.5.zip'
Content type 'application/zip' length 3619051 bytes (3.5 MB)
downloaded 3.5 MB

package 'arm' successfully unpacked and MD5 sums checked
package 'mi' successfully unpacked and MD5 sums checked
package 'TH.data' successfully unpacked and MD5 sums checked
package 'sem' successfully unpacked and MD5 sums checked
package 'rgl' successfully unpacked and MD5 sums checked
package 'multcomp' successfully unpacked and MD5 sums checked
package 'lmtest' successfully unpacked and MD5 sums checked
package 'leaps' successfully unpacked and MD5 sums checked
package 'aplpack' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\Amy Albin\AppData\Local\Temp\RtmpGiUQcd\downloaded_packages

Rcmdr Version 2.7-2


Attaching package: 'Rcmdr'

The following object is masked from 'package:base':

    errorCondition

Warning messages:
1: package 'Rcmdr' was built under R version 4.0.5
2: package 'RcmdrMisc' was built under R version 4.0.5
3: package 'sandwich' was built under R version 4.0.5
4: package 'effects' was built under R version 4.0.5
> library(Rcmdr)
> bootResults<-boot(statistic = bootReg, formula = sales ~ adverts + airplay +$
Error in NROW(data) : object 'album2' not found
> album2<-read.delim("Album Sales 2.dat", header = TRUE)
>
> bootResults<-boot(statistic = bootReg, formula = sales ~ adverts + airplay +$
Error in t.star[r, ] <- res[[r]] :
  number of items to replace is not a multiple of replacement length
> object<-boot(data,function,replications)
Error: unexpected ',' in "object<-boot(data,function,"
> object<-boot(data, function, replications)
Error: unexpected ',' in "object<-boot(data, function,"
> object<-boot(data function, replications)
Error: unexpected 'function' in "object<-boot(data function"
>
> object<-boot(datafunction, replications)
Error in NROW(data) : object 'datafunction' not found
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Album Sales 2.dat
Type: application/octet-stream
Size: 3365 bytes
Desc: not available
URL: <http://nfbnet.org/pipermail/blindrug_nfbnet.org/attachments/20220308/ee530027/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Album Sales 1.dat
Type: application/octet-stream
Size: 2363 bytes
Desc: not available
URL: <http://nfbnet.org/pipermail/blindrug_nfbnet.org/attachments/20220308/ee530027/attachment-0001.obj>


More information about the BlindRUG mailing list