R Studio How To
R Studio How To
CONFIDENCE INTERVALS.............................................................................................................................................. 6
ESTIMATE A 90% CONFIDENCE INTERVAL ................................................................................................................................. 6
ESTIMATE A 95% CONFIDENCE INTERVAL ................................................................................................................................. 6
ESTIMATE A 99% CONFIDENCE INTERVAL ................................................................................................................................. 6
ESTIMATE A P-VALUE T-DISTRIBUTION ...................................................................................................................................... 6
attach a dataset
attach(name of the dataset)
example – attach(data)
save a dataset
save(name of the new dataset,file="name of the file.Rda")
example - save(combined,file="inc_literacy_2016.Rda")
combine dataframes
NewDatasetName <- cbind(NameOfDataframe1, NameOfDataframe1,..)
example - combined <- cbind(temp,literacy[,"X2016"])
rename a dataset
NewName <- OldName
estimate the integral from −∞ to q of the pdf of the normal distribution where q
is a Z-score
pnorm(value)
estimate the density function for the t distribution with df degrees of freedom
dt(value, df)
estimate the quantile function for the t distribution with df degrees of freedom
qt(value, df)
produce a histogram
hist(name_of_variable)
library(corrplot)
corrplot(Correlation_Matrix,method="number",type="lower")
or
corrplot(Correlation_Matrix,method="number",type="upper")
or
corrplot(Correlation_Matrix,method="circle")
or
corrplot(Correlation_Matrix,method="pie")
or
corrplot(Correlation_Matrix,method=="color")
Here you can find additional commands on how to modify your correlation matrix.
or
H0 <- c("Variable_name_1 = 0", " Variable_name_2= 0")
#we have specified each parameter = 0 to separately, but the function runs the test of both jointly, so it is a
joint test
linearHypothesis(Name_the_model, H0)
If the p-value is less than the significance level we have to reject the null hypothesis, therefore that implies
that the residuals are heteroscedastic.
If the p-value is greater than the significance level we have to accept the null hypothesis, therefore that
implies that the residuals are homoscedastic.
library(tseries)
name_the_model < - lm(dependent_variable ~ independent variable_1 + independent variable_2,…)
summary (Name_the_model)
If the p-value is less than the significance level we have to reject the null hypothesis, therefore that implies
that the residuals are not normally distributed.
If the p-value is greater than the significance level we have to accept the null hypothesis, therefore that
implies that the residuals are normally distributed.
200 is just a random number that needs to be adjusted depending on the data under investigation.
estimate the OLS model using the in-sample and out-of-sample period
name_the_model < - lm(dependent_variable ~ independent variable_1 + independent variable_2,…, data=
In_Sample_Period)
summary (Name_the_model)
or
name_the_model < - lm(dependent_variable ~ independent variable_1 + independent variable_2,…, data=
In_Sample_Period)
summary (Name_the_model)
errors <- resids (name_the_model)