error code on linear regression model

Im trying to run a linera regression model. I've ran this code before so I'm copy and pasting it from the r script.
This is the code I ran:

plot(latentmean_FA~ind_total_OFS, data=mydata,
       +      main="Human Rights in Latin America by United States Foriegn Direct Investment",
       +      xlab= "U.S. Foreign Direct Investment",
       +      ylab= "Respect for Human Rights in Host Country")

This is the error I got:

> plot(latentmean_FA~ind_total_OFS, data=mydata,
+        +      main="Human Rights in Latin America by United States Foriegn Direct Investment", 
Error: unexpected '=' in:
"plot(latentmean_FA~ind_total_OFS, data=mydata,
       +      main="
+      xlab= "U.S. Foreign Direct Investment",
Error: unexpected ',' in "       +      xlab= "U.S. Foreign Direct Investment","
 +      ylab= "Respect for Human Rights in Host Country")
Error: unexpected ')' in "       +      ylab= "Respect for Human Rights in Host Country")"

Does anyone know how I could fix this?

When you copy code from the console you need to delete the > and + signs after you paste it into a script.

Your code will produce a scatterplot but not a regression line. I use ggplot( ) instead of plot( ) so am unfamiliar with the latter, but I think you could run this after the plot code to add a fitted line to the scatterplot:

abline(lm(latentmean_FA ~ ind_total_OFS, data = mydata))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.