library(purrr)
finalResult = purrr::map_df(unique(LE_GDP_C$year), function(modelYear){
myModel = lm(sqrt(LE) ~log_gdp, data = LE_GDP_C %>% filter(year == modelYear) %>% select(-year))
data.frame(year = modelYear, RSquared = summary(myModel)$r.squared)
}
)
We need same sample data and more of your code. Please look at
FAQ: How to do a minimal reproducible example ( reprex ) for beginners for some suggestions.
require(readxl)
require(dplyr)
require(tidyverse)
require(ggplot2)
getwd()
LE_A = read_xls("LE.xls")
LE_A = as.data.frame(LE_A)
#Selecting the columns necessary for Linear Regression evaluation
LE_GDP = select(LE_A, LE, GDP, Inc_resources, Year, Country, Status, Population)
LE_GDP_C = na.omit(LE_GDP)# Omit the N/A values
LE_GDP_C$log_gdp = log(LE_GDP_C$GDP) # added new variable log_gdp instead of mutating GDP
str(LE_GDP_C)
datapasts::df_paste(head(LE_GDP_C,6))[,c('LE' , 'log_gdp' , 'Year')]
# I want to do linear regression over years
finalResult = purrr::map_df(unique(LE_GDP_C$year), function(modelYear){
myModel = lm(sqrt(LE) ~log_gdp, data = LE_GDP_C %>% filter(year == modelYear) %>% select(-year))
data.frame(year = modelYear, RSquared = summary(myModel)$r.squared)
}
)
I don't know how to upload the sample data
That link should suggest some ways. However, a very simple and very effective way to supply some data is to use the dput() command.
dput(mydata)
where mydata is the name of your dataframe or tibble,
and then simply copy the output and paste it here.
If you have a very large data set then a sample should be fine. To supply us with 100 rows of your data set do
dput(head(mydata , 100))
```
copy and paste.
system
Closed
6
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.