please help i can't get the estimation regression equation right on studio always i get that Error: unexpected symbol in "model.frame(fdi~trade openness"
Hi @amarta and welcome the RStudio Community
I'd like to give you a quick tip. Whenever you ask a question on this forum (and on any forum really), it is important that you provide all the necessary information for people to help you. In your case, you tried to estimate a linear regression. So, helpful information to provide would be:
- the relevant code and...
- your data or any data that would help run your code
This is usually referred to as a reproducible example. You may want to consult this great article to learn more about it: FAQ: How to do a minimal reproducible example ( reprex ) for beginners
Now, about your question, even though we have limited information, it seems that the source of your problem is: trade openness
. R variable do not usually have spaces in them (even though it's possible). So what is exactly the name of that variable? It may be trade_openness
or trade.openness
or something like that!
Thank you I think that what is happening
on my file i have trade openness with space,
thank
Then you should rename the variable.
These are my variables
(Fdi =dependent variable) trade openness, corruption, government effectiveness and political effectiveness =independent
excel_file <- read_excel("Desktop/excel file.xls")
View(excel_file)
library(readxl)
excel_file <- read_excel("Desktop/excel file.xls",
-
col_types = c("text", "blank", "numeric",
-
"numeric", "numeric", "numeric",
-
"numeric", "numeric", "numeric",
-
"numeric", "numeric"))
Dear Gueyenono
please help this what i am getting all the time
model=lm(fdi~trade_openness+governance_effectiveness+politicl_stability+corruption+GDP_total+GDP_per_capita+population_total,data=excel_file)
Error in eval(predvars, data, env) : object 'fdi' not found
@amarta Once you import your dataset, run the following code:
dput(excel_file)
then copy and paste the output here.
your help is very much apreciated
dput(excel_file)
structure(list(FDI = c(-3.23, -3.02, -1.46, -7.12, 3.66, 10.03,
-0.18, -7.4, -6.46, -4.1, 0.12, 0.1, 0.13, 0.09, 0.18, 0.1, 0.13,
0.11, 0.11, 0.11, 2.73, 1.98, 0.99, 0.58, 0.17, 0.23, 0.05, 0.3,
0.4, 0.45, 0.03, 0.03, 0.01, 0.02, 0.03, 0.02, 0.01, 0.02, 0.02,
0.03, 1.26, 3.66, 5.64, 6.7, 5, 3.87, 3.13, 2.32, 2.68, 2.18,
0.05, 0.03, 0.02, 0.01, 0.03, 0.03, 0.02, 0.03, 0.02, 0.03),
Trade_openness = c(104.12, 99.98, 91.8, 86.81, 79.33, 62.89,
53.37, 52.26, 66.38, 0, 94.44, 99.85, 100.28, 95.34, 101.05,
104.07, 104.19, 113.3, 117.27, 116.21, 144.67, 114.38, 116.68,
106.89, 104.38, 98.88, 92.6, 102.43, 104.51, 107.38, 50.13,
56.62, 41.17, 44.08, 51.59, 59.78, 57.81, 60.85, 57.79, 57.01,
70.79, 80.23, 101.87, 103.15, 111.47, 93.91, 105.64, 99.72,
131.99, 112.15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Government_effectiveness = c(-1.12,
-1.15, -0.99, -1.22, -1.12, -1, -1.04, -1.03, -1.05, -1.12,
-0.02, 0.15, 0.12, 0.1, 0.07, 0.17, 0.13, 0.17, 0.32, 0.29,
-1.68, -1.63, -1.61, -1.54, -1.5, -1.42, -1.41, -1.44, -1.29,
-1.34, -1.03, -1.03, -1.23, -1.43, -1.58, -1.61, -1.64, -1.77,
-1.49, -1.51, -0.58, -0.64, -0.63, -0.61, -0.72, -0.75, -0.86,
-0.89, -0.87, -0.82, -0.79, -0.7, -0.68, -0.73, -0.82, -0.75,
-0.67, -0.75, -0.64, -0.63), Political_stability = c(-0.23,
-0.37, -0.39, -0.39, -0.33, -0.5, -0.32, -0.33, -0.32, -0.31,
0.84, 0.72, 0.81, 0.78, 0.35, 0.87, 0.89, 0.77, 0.85, 0.88,
0.24, 0.15, 0.23, 0.12, -0.37, -0.21, -0.14, -0.17, -0.08,
-0.19, -0.69, -0.75, -0.97, -0.9, -0.71, -0.52, -0.44, -0.5,
-0.68, -0.56, 0.39, 0.33, 0.39, -0.23, -0.34, -0.51, -1.09,
-0.93, -0.81, -0.75, 0.12, 0.01, 0.01, 0.11, 0.18, 0.14,
0.22, 0.19, 0.53, 0.52), Corruption = c(19, 20, 22, 23, 19,
15, 18, 19, 19, 26, 51, 55, 60, 58, 57, 55, 59, 55, 57, 58,
19, 19, 20, 19, 19, 0, 0, 17, 16, 16, 0, 0, 25, 19, 19, 17,
16, 17, 16, 18, 27, 27, 31, 30, 31, 31, 27, 25, 23, 26, 30,
30, 42, 42, 42, 42, 46, 46, 46, 46), Economic_freedom = c(48,
46, 47, 47, 48, 48, 49, 49, 49, 51, 62, 65, 64, 64, 66, 66,
67, 57, 60, 63, 49, 48, 43, 42, 44, 40, 44, 45, 42, 41, 44,
47, 50, 51, 51, 52, 52, 56, 57, 54, 56, 57, 57, 55, 55, 55,
53, 50, 46, 49, 49, 50, 50, 48, 49, 53, 57, 55, 54, 54),
GDP_total = c(83.8, 111.79, 128.05, 136.71, 145.71, 116.19,
101.12, 122.12, 101.35, 94.64, 1.66, 1.87, 1.74, 1.85, 1.86,
1.6, 1.66, 1.77, 1.97, 1.98, 16.31, 21.36, 22.39, 21.95,
21.77, 13.19, 11.24, 12.2, 13.28, 11.03, 0.85, 1.1, 0.99,
1.05, 1.05, 1.05, 1.18, 1.35, 1.46, 1.34, 11.09, 14.38, 16.35,
16.97, 17.72, 15.95, 11.94, 13.22, 14.72, 14.93, 0.2, 0.23,
0.25, 0.3, 0.35, 0.32, 0.35, 0.38, 0.42, 0.43), GDP_per_capita = c(3587.88,
4615.47, 5100.1, 5254.88, 5408.41, 4166.98, 3506.07, 4095.81,
3289.65, 2973.59, 3378.25, 3740.39, 3447.52, 3615.98, 3588.67,
3043.01, 3130.96, 3292.65, 3617.33, 3603.78, 17288.86, 21641.87,
21711.15, 20390.72, 19394.03, 11283.47, 9250.33, 9667.91,
10144.2, 8131.92, 557.63, 702.74, 616.41, 634.48, 622.48,
603.16, 661.01, 736.73, 777.97, 697.78, 471.18, 594.59, 657.65,
664.08, 673.97, 589.86, 428.93, 461.42, 498.96, 491.8, 1094.71,
1263.87, 1340.53, 1577.02, 1782.8, 1595.86, 1710.13, 1811.01,
2001.14, 1994.91), Population_total = c(23.36, 24.22, 25.11,
26.02, 26.94, 27.88, 28.84, 29.82, 30.81, 31.83, 0.49, 0.5,
0.51, 0.51, 0.52, 0.52, 0.53, 0.54, 0.54, 0.55, 0.94, 0.99,
1.03, 1.08, 1.12, 1.17, 1.22, 1.26, 1.31, 1.36, 1.52, 1.56,
1.6, 1.65, 1.69, 1.74, 1.78, 1.83, 1.87, 1.92, 23.53, 24.19,
24.86, 25.56, 26.29, 27.04, 27.83, 28.65, 29.5, 30.37, 0.18,
0.18, 0.19, 0.19, 0.2, 0.2, 0.2, 0.21, 0.21, 0.22)), row.names = c(NA,
-60L), class = c("tbl_df", "tbl", "data.frame"))
Sorry is a very long observations
Okay, I see where your problem comes from. You need to keep "case sensitivity" in mind. So, if your variable is Trade_openness
, you should respect the fact that the first letter is a capital T
. If you write trade_openness
(with a lowercase t
), you will get an error. In your code, you wrote fdi
instead of FDI
for example and you also made a few other typos. These kinds of mistakes are very frequent so be careful what you write
The following code will work:
model <- lm(FDI ~ Trade_openness + Government_effectiveness + Political_stability + Corruption + GDP_total + GDP_per_capita + Population_total, data = excel_file)
summary(model)
Call:
lm(formula = FDI ~ Trade_openness + Government_effectiveness +
Political_stability + Corruption + GDP_total + GDP_per_capita +
Population_total, data = excel_file)
Residuals:
Min 1Q Median 3Q Max
-5.9142 -0.5985 -0.0902 0.4139 11.5099
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.187e-01 2.753e+00 0.334 0.739996
Trade_openness 4.982e-03 1.119e-02 0.445 0.658103
Government_effectiveness 6.264e-01 1.573e+00 0.398 0.692123
Political_stability 7.734e-02 1.322e+00 0.059 0.953562
Corruption -2.418e-02 4.693e-02 -0.515 0.608522
GDP_total -4.906e-02 1.265e-02 -3.879 0.000297 ***
GDP_per_capita 9.058e-05 1.107e-04 0.818 0.416986
Population_total 1.305e-01 4.826e-02 2.704 0.009234 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.521 on 52 degrees of freedom
Multiple R-squared: 0.2812, Adjusted R-squared: 0.1845
F-statistic: 2.907 on 7 and 52 DF, p-value: 0.01213
Dear Gueyenono
Thank you very much for your help,
mine did not come out as yours
Coefficients:
(Intercept) Trade_openness Government_effectiveness
-1.4164253 0.0018369 0.7860765
Political_stability Corruption Economic_freedom
-0.1272064 -0.0393625 0.0565633
GDP_total GDP_per_capita Population_total
-0.0489966 0.0001299 0.1329807
Would you please also share your code with me? Otherwise, I will not be able to tell you why our results are different.
Sorry, what is the code please can you specify
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.