



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




INSERIRE LA DIRECTORY : File-> Cambia directory…-> Seleziona la cartella
MOSTRA L’ATTUALE DIRECTORY: getwd()
MOSTRA I FILE CONTENUTI NELLA DIRECTORY: list.files()
CARICA UN FILE: load(“ namefile ”)
CARICA LE FUNZIONI: library(MASS)
ISTOGRAMMA : hist( namevariable )
SCATTERPLOT: plot ( namematrix $ variable1, namematrix$variable2 )
BOXPLOT WITH JUST ONE VARIABLE : boxplot( namematrix $ variable )
BOXPLOT WITH MORE VARIABLES : boxplot( namematrix $ variable1, namematrix$variable2 )
GRAPHICAL DISPLAY OF CORRELATION MATRIX: pairs( name matrix )
abline(nome matrice)
Dopo aver inserito la directory e il set di dati, cerchiamo di trovare le prime informazioni sui dati:
WORKSPACE: ls()
LE PRIME 6 RIGHE DELLA MATRICE: head ( namematrix )
DIMENSIONE DELLA MATRICE: dim(namematrix)
RIASSUNTO DELLE INFORMAZIONI : summary(namematrix)
oppure
Oppure potrebbe dare un set di dati tipo, quindi in questo caso dobbiamo creare prima singolarmente i
vettori e poi creare la matrice. Esempio:
x1<- c (45, 69, 58, 58, 62)
x2<- c (2.23, 2.69, 2.14, 8.25, 2.12)
x3<- c (154, 186, 136, 201, 222)
A<- cbind(x1,x2,x3)
STANDARDIZZARE I VALORI : scale ( namematrix )
CREARE COVARIANCE MATRIX: var ( nomedellamatricestandardizzata )
CREARE CORRELATION MATRIX: cor ( namematrix )
SPECTRAL DECOMPOSITION OF THE CORRELATION MATRIX: eigen( nomecorrelationmatrix )
In questo modo si ottengono due matrici:
prcomp(A)
SCREEPLOT: graphical representation of the variability of each principal component on the total variability.
plot(nome della matrice degli eigen$values, type=”o”)
MATRICE INVERSA: solve( namematrix )
DETERMINANTE : det( namematrix )
MATRICE TRASPOSTA: t(namematrix)
INNER PRODUCT: t(a) %*% a
OUTER PRODUCT: a %*% t(a)
list.files()
read.table("datiSenil.txt")
read.table("datiSenil.txt", header=TRUE)
Dove “a” è il nome della matrice originaria
CALCOLARE SOMMA RESIDUALS : sum(e) (deve venire circa 0)
CALCOLARE DEVIANZA DI E : sum(e^2)
CALCOLARE LA DEV(R): sum [(nomevariabileY-mediavariabileY)^2]
CALCOLARE R^2: 1-[DEV(E)/DEV(R)]
COMANDO PER SINTETIZZARE TUTTO: lm( nomevariabileY~nomevariabileX )
the logit distribution function (similar but lower to the normal distribution) # μ = (e^(βo+β1X1+…+βpXp))/(1+(e^(βo+β1X1+…+βpXp))).
the 0-1 range of the binary variable) and heteroscedasticity (the opposite of the omosckedasticity required by the LDM).
can't easily explain the parameters and you can't obtain odds ratio.
# Odds #Ratio between probability of success (G1) and probability of unsuccess (G0). #"The probability of G1 is Odds more times the probability of G0" #Larger it is, larger the probability of success is. #If 1 there is no association.
# Odds ratio # ψx|A/ψx|B. #Ratio between probability of G1 for category A and probability of G1 for category B. #"Moving from A to B increase the possibility of G1 of OddsRatio100%" (categorical variable), "The probability of G1 increase of OddsRation100% for unit increase of X" (numerical variable). #Can vary from 0 to +INF, with a range from 0 to 1 identifying negative association, 1 identifying no association and a range from 1 to +INF identifying positive association. exp(b1') # Inverse Odds Ratio # ψx|B/ψx|A. #"Moving from A to B decrease the possibility of G1 of InverseOddsRatio100%" (categorical variable), "The probability of G1 decrease of OddsRation100% for unit increase of X" #Useful to have a better understanding of Odds Ratio when β1 is negative. 1-exp(b1') # LM LM<-glm(G~X+factor(Y), family=binomial(logit)) #1. #G is the binary variable #Factor() produces dummy variable and is needed only for non-binary categorical variable. #To use the normal distribution, instead of logit set probit. sLM<-Summary(LM) #2. sLM$coefficients #Estimate (Intercept) #Regression coefficient βo'. #Average value when all the variables are 0. sLM$coefficients #Estimate (X) #As LMR's estimate (X). #A negative value would produce an Odds Ration under 1 and so identify a negative association (and vice versa; the same for the others Coefficients Estimates). Alessandro Li Vigni
sLM$coefficients #Estimate (Y(B)) #Regression coefficient β2' for the dummy variable Y from A to B. sLM$coefficients #Estimate (Y(C)) #Regression coefficient β2' for the dummy variable Y from A to C. #The inverse odds ratio would be from C to A. sLRM$coefficients #z value #As LRM's t value. sLRM$coefficients #Pr(>|t|) #As LRM's Pr(>|t|). #To define the best covariates patterns (highest overall probability of G1) is needed to take all negatively-associate covariates' lowest value and all the positively- associate covariates' highest value, and ordering them in decreasing order starting from the one with the highest t value LRMs$coefficients #Signif. codes #As LRM's Signif. codes. # Covariates pattern probability #Useful to identify the probability of success of a theoretical observation with certain value in the covariates. C<-exp(b0+…) #1 #For numerical covariates, it's needed to add the relative regression coefficient multiplied for the value which we want to set. #For categorical covariates, it's needed to add the regression coefficient of the category which we want to set #If we want to set a covariate to the base value, it's needed to omit its coefficient. (C/1+C)*100 #2.