seabroadlab / reviewlab

private documents for 리뷰
0 stars 0 forks source link

Basic

Questions&Help

type ??functionname

Data composition

N X P matriced data; N row and P colum, N observations with P variables

Char and String and Numerical variable

if you type c("something","Hello") it generates the Char values

Subset Function

Just like logical function of MATLAB, it can substract the subset from the dataset and make it into specific(another) dataset
subset

Capital Letters

R specifies the capital letters different from the lower letters

Read and Load

Getwd(); get working directory file that we are using setwd(); set the directory addresses

Intro to practically use the R for analysis

Assigning variables

"<-" and "=" is little different, "<-" is preferred since the "=" has multiple meanings.(e.g. maybe logical equations?)

Packages

To use the package, firstly,install it by using command install.packages("psych")

And load the package into working environment by library(psych)

Load the data file

".csv" files are commonly used. It's short for "comma seperated values" files. e.g. spreadsheets, Google Sheets, Microsoft Excel etc....
Give the data frames a useul name
e.g. data1, RegDat1 ... dat1<-read.csv(file="filename.csv", header=T, stringsAsFactors = F)
in here, the header means whether you want to take the very first row to the variable names(True, T) or not (False, F)
Also, if you want to treat the categorical variables(e.g. Gender(female, male)) as the binomial, you can set it by
stringsAsFactors = True(or T)

Indexing and modifying the data elements from file

d[10,23]
It indexes the date element in 10th colum and 23rd row
colnames(dat1)[1] <- "something_you_want_to_use_it_as_variablename"
() specifies dataset and []_ specifies which column you want to change it to specific variable name

Various useful functions

summary(dat1) : getting the basic descriptives from data file "dat1"
View(dat1) : it makes able to read data file "dat1" in FANCY data frame on console. ( if you just type dat1 in console, it literally will Print dat1 on console
colnames(dat1)[1] or dat1$State, you can index the the 1st column of data file dat1 or Varialbe named State in data file dat1

Manipulating Data

If we want to deselect, get rid of certain variables from dat1, we can use variable methods. Two are basics.
dat1_modified <- cbind(dat1[,1:7], dat1[,11:18])
dat1_modified1 <- rbind(dat1[1:7,], dat1[11:18,])
OR
Use codes like belows,
dat1_modified2 <- dat1[,-8:-10]
dat_modified3 <- dat1[-8:-10,]

Plotting and Test Analysis

Correlation

corr_matrix$Call :If you type it you can see what you've did to the corr_matrix and track the changes or variables you are using

Standardization

scale(datafile[

T-test

t.test(d[,], d[,]),
Usually it require datasets to be kind of in line to each other(maybe dimensions?) OR
Other ways to do it with using variables neames
t.test(d$QualityOfLife[1:25], d$QualityOfLife[26:50])

ANOVA

anova(X,Y) ,
you can put even models in X and Y

Regression

Plotting Interaction

interact_plot(model_5, pred=Neuroticism, modx=Extraversion)
use the variables from interaction of interest
high E and N is associated with high unemployment; high E and low N is associated with low unemployment
N is not related to unemployment when E is low
we can plot it with Neuroticism as the moderator too. Theory must lead the way here