Watts-College / cpp-523-fall-2021

https://watts-college.github.io/cpp-523-fall-2021/
1 stars 3 forks source link

Lab 2 – Can’t get Loaded Data to Output #4

Open mluna11 opened 2 years ago

mluna11 commented 2 years ago

Hi,

I can’t get the loaded data to output in R Studio. When it does output, it's in an HTML type format.

When I run the below chunk of script, I get nothing. I believe I'm supposed to get a table as referenced here.

# do not change this chunk

# load data
URL <- "https://raw.githubusercontent.com/DS4PS/cpp-523-fall-2019/master/labs/class-size-seed-1234.csv"
dat <- read.csv( URL )

# load draw_ci function
source( "https://raw.githubusercontent.com/DS4PS/sourcer-r/master/sourcer.R" )

Then when I run this chunk of script:

# do not change this code 

library( stargazer )

m1 <- lm( test ~ csize, data=dat  ) 
m2 <- lm( test ~ csize + tqual, data=dat )
m3 <- lm( test ~ tqual + ses, data=dat ) 
m4 <- lm( test ~ csize + ses, data=dat  )
m5 <- lm( test ~ csize + tqual + ses, data=dat  )

stargazer( m1, m2, m3, m4, m5, 
           type = "html", digits=2,
           dep.var.caption = "Dependent Variable: Test Scores",
           # dep.var.labels = "",
           dep.var.labels.include = FALSE,
           omit.stat = c("rsq", "f", "ser"),
           column.labels = c("Model 1", "Model 2", "Model 3", "Model 4", "Model 5"),
           covariate.labels=c("Classroom Size",
                              "Teacher Quality",
                              "Socio-Economic Status",
                              "Intercept"),
           notes.label = "Standard errors in parentheses")

The output I get looks like this: Lab 2 Table Output

Can someone please help me figure out what I'm doing wrong? Is there a package that I need to install to get the tables to load and get them in their correct readable formats?

madisonfrazee commented 2 years ago

I had this same problem! I just ignored the first chunk of script (I think it is supposed to be there). Then, to get the coefficient plots, you need to update the code in each model. You will need to replace the b1 and se values, then the plots should come out correctly.

What I did was replace all of the b1 and se plots for each model first, and then I ran the entire code once I was finished. Let me know if that helps!

# replace value with correct b1 and SE for the question
**b1 <- (put b1 here)
se <- (put se here)**

# do not change code below 

upper.ci <- b1 + 1.96*se 
lower.ci <- b1 - 1.96*se
plot( c(lower.ci,upper.ci), c(1,1), 
      xlim=c(lower.ci-0.5,1), ylim=c(0,3),
      xlab="", ylab="", axes=F, bty="n",
      type="l", lwd=3, col="darkorange", 
      main="Model 2" )
points( b1, 1, col="darkorange", pch=19, cex=3 )
text( b1, 1, b1, pos=3, col="gray30", cex=1.5, offset=1 )
text( c(lower.ci,upper.ci), 1, round(c(lower.ci,upper.ci),2), 
      pos=c(2,4), cex=0.8, col="gray40")
abline( v=0, lty=2, lwd=2, col="gray40" )
axis( side=1, at=0, labels="B1=0" )
dholford commented 2 years ago

Hello,

I actually think the html output in R is what is supposed to happen. If you look in that code chunk you'll notice it says type = "html". When you knit the RMD file as an html doc it will turn the html output in R studio into the actual visual. R Studio just doesn't turn the html code into visuals within itself, only in the actual html output.

Best, Dylan