Watts-College / cpp-523-fall-2021

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

Lab 06 Error in R #15

Open ebossert opened 2 years ago

ebossert commented 2 years ago

Is anyone else having this issue with knitting the file to HTML? I keep getting this error message when I try to knit to view the regression table. image It says that the y_hat is the issue and when the graph is plotted the regression line doesn't appear so I guess that may be why. I also don't know why it refers to Line 29 when that's just the URL info. image

lecy commented 2 years ago

@ebossert knitting which file? The lab template works alright.

You are pulling this example from the instructions, correct? Try:

URL <- "https://raw.githubusercontent.com/DS4PS/cpp-523-fall-2019/master/labs/data/IncomeHappiness.csv"
dat <- read.csv( URL )

dat$income2 <- dat$income^2
m1 <- lm( happiness ~ income + income2, data=dat )
y_hat <- predict( m1, data.frame( income=1:200000, income2=(1:200000)^2 ) )

plot( dat$income, dat$happiness, 
      xlab="Income (Thousands of Dollars)", ylab="Hapiness Scale",
      main="Does Money Make You Happy?",
      pch=19, col="darkorange", bty="n",
      xaxt="n" )
axis( side=1, at=c(0,50000,100000,150000,200000), labels=c("$0","$50k","$100k","$150k","$200k") )
lines( 1:200000, y_hat, col=gray(0.3,0.5), lwd=6 )
ebossert commented 2 years ago

I replaced the code in that chunk with what you provided and it was able to knit just fine. I originally used the code provided in the Lab 06 instructions, but I must have accidentally mistyped something because when I tried that code again it also worked fine. Classic user error, thanks for the help!

danafuller commented 2 years ago

I am also getting an error when I try to knit the lab. It reads: Line 65 Error: object of type 'closure' is not subsettable

Line 65 is the first line in this code chunki:

y.happy <- dat$happiness
x.income <- dat$income / 10000  
x2.income.sq <- x.income*x.income
summary( lm( y.happy ~ x.income + x2.income.sq ) )
stargazer( n, type="html",
           omit.stat = c("rsq","f","ser"),
           notes.label = "Standard errors in parentheses" )
lecy commented 2 years ago

The error mean the dataset is probably not loaded correctly, or was altered in an unexpected way.

It may have happened earlier in the file than where the error occurs so you would need to share some of what you are doing.

Alternatively you can work from the top and run chunks one at a time until you see where the dataset is altered.

danafuller commented 2 years ago

@lecy Is there an undo changes button? I just accidentally erased my lab.

lecy commented 2 years ago

In R or R Studio?

you can save your R History file if you have not closed the console.

R Studio has an auto save for RMD docs but that depends on if you saved it.

if you files are in Dropbox there is also a way to roll back files there.

danafuller commented 2 years ago

It is in R Studio. I made a mistake and didn't know how to return it back to normal so I just closed it and it asked if I wanted to save changes. I said no, thinking it would revert back to my previous version, but it was completely gone. How do I check that R History file just in case I can retrieve it? It was completely done it just wouldn't knit to html

lecy commented 2 years ago

https://stackoverflow.com/questions/35223435/how-to-get-unsaved-script-tabs

Is this useful?

danafuller commented 2 years ago

@lecy Thank you for that resource. I looked at it, but ultimately I thought it would be quicker just to start my lab over rather than troubleshoot with my remedial level R knowledge. Thank you so much for trying to help me!

lecy commented 2 years ago

I hope it went quickly the second time!