r/R_Programming • u/ceciliahslee • Dec 07 '17
Best Introduction to R Programming
r/R_Programming • u/ceciliahslee • Dec 07 '17
r/R_Programming • u/[deleted] • Jun 26 '16
Is there any advantage to using <- over = ? To me it is two characters to type vs one, so why would you do this?
r/R_Programming • u/smgigi • Apr 04 '16
If you are struggling with learning R, visit here. Codes are straightforward. I comment on every single line of R codes.
r/R_Programming • u/crmercado • Jan 26 '18
I've been working in R for a few years now. I'm looking for a new job and I thought it'd be a fun portfolio project to create a Shiny app that actually converts a Job Description (or an "About Us" page) into a colorful wordcloud.
I added the following customization: You add the text into the text box.
Then you select how many "n-grams" (word pairs) you'd like to put on the cloud. For example "chicken sandwich" is a 2-gram, "cheese chicken sandwich" is a 3-gram.
The wordcloud automatically removes punctuation, foreign letters, stopwords ("i","me","not","do","is","a","the"... there's a list available in the tm package), and makes it all lowercase.
I don't want to use up all my shinyapps.io hours but here's the code:
ui code - https://github.com/CR-Mercado/General-Data-Science/blob/master/ui.R
server code - https://github.com/CR-Mercado/General-Data-Science/blob/master/server.R
A nonsense test case is included at the bottom of the server code.
If you've never run a shiny app before it's easy!
Open R Studio (use a completely fresh environment)
File -> New File -> Shiny Web App -> Name it! and select multiple files.
erase and replace everything in the ui.r and server.r scripts
hit run app
If there are any errors- it's most likely because you need to install.packages() whatever packages I used that you don't have. such as: shiny, tm, wordcloud, RColorBrewer, dplyr, plyr (load dplyr THEN load plyr after)
If you have any questions about this or other R programming questions, I'll try to be available here on R_Programming more often, but feel free to shoot me a message (check StackOverflow too, it's the best).
r/R_Programming • u/clementwalter • Dec 13 '17
r/R_Programming • u/0lad1 • Nov 10 '16
Don't know if it's appropriate to post this here, but any help will be appreciated.....
So I'm working on my PhD in applied statistics and my advisor has asked me to write a function to conduct Joint Maximum Likelihood Estimation for the rasch IRT model.
.... The thing is I already know that the function exists in an package and I've been looking through the package/source file to try to understand how it works so I can create my own.
I've found this task a little tedious/ somewhat above my skill level.
What is the best way for me to recreate this function?
Is anyone aware of a tutorial/video that could be helpful?
Thanks in advance
r/R_Programming • u/fooliam • Jul 18 '16
Hi folks. I'm trying to teach myself R using R studio. I've been using swirl based on a recommendation from learntoprogram, and I've completed their beginner courses and am about to finish their intermediate courses.
I'm hoping that you folks can tell me some other resources to continue learning and practicing with R.
Got anything for me?
Thanks!
r/R_Programming • u/[deleted] • Jun 27 '16
I am very new to R programming. I just started learning it as I am applying for Data analytics related jobs. Giving suggestions on cracking interviews will be very helpful.
r/R_Programming • u/chill-with-will • Jun 15 '16
I have a 2622x36 dataset of corn/acre yields that looks like:
FIPS |1981|1982| ... |2015
1234|50 |75 | ... | NA
5678| 45 |NA | ... | 52
FIPS is a code for state/county. I want to forecast/predict a 2016 column. I have NA values
My first plan was to do a simple linear regression of each row, one at a time, with a loop. However, this inserts an assumption into my model that each FIPS is independent of one another, whereas they are actually interrelated. I was told I could capture this interrelation into my 2016 predictions using dummy variables, but I never saw anything like this in school (which may be why I sort of have no idea where to begin--I'm not even sure what to Google or if the title of this thread is relevant).
Any hints like functions to read up on, or examples to study, would be greatly appreciated!
**Edit: Figured it out, I think, using this video: https://www.youtube.com/watch?v=2s8AwoKZ-UE
First I went back to using my dataset that has 3 columns: FIPS, Year, and BushelsPerAcrePlanted. Then I changed the class of FIPS from integer to factor, filtered out the NA values, then used lm(), which automatically made my dummy variables for FIPS.
mydata$FIPS<-as.factor(mydata$FIPS)
mydata$FIPS<-filter(mydata, !is.na(mydata$FIPS)
model<-lm(mydata$BushelsPerAcrePlanted ~ mydata$FIPS + mydata$Year)It takes 10 minutes or so to run because I have 2622 different FIPS. Now I can produce a BushelsPerAcre = X_FIPS x FIPSCoefficient + 2016 x YearCoefficient as soon as I figure out the predict.lm() function
**Edit2:
predictions2015 <- predict(model,newdata = data.frame(Year = rep(2015,length(yields2$FIPS))))This code is giving me some funky output. For my first FIPS, 10001, it gives me values that start around 87 and then trend up to 136, over the course of 1981 to 2015. Then the next FIPS comes up, and it starts around 82 and trends up to 134. I expected to get a set of identical numbers for each FIPS, since I tried to set Year=2015 for all rows... I think it's clear I've got a syntax issue that I still need to figure out. Note that I decided to predict 2015, since then I can compare to my observed 2015 yield values.
Data illustrated:
FIPS | Year | Predicted2015Yield | What I was expecting
10001 | 1981 | 87 | 136
10001 | 1982 | 88 | 136
10001 | 1983 | 90 | 136
... | ... | ... | ...
10001 | 2014 | 134 | 136
10001 | 2015 | 136 | 136
10002 | 1981 | 82 | 134
10002 | 1982 | 83 | 134
and so on
Hey I figured it out! Perseverance, that's the answer:
#Create a set of inputs for making predictions with. First a column of 70,158 "2015"s
Year2015<-data.frame(Year = rep(2015,length(yields2$FIPS)))
#Now combine that column with a column of my FIPS into a data frame:
predictors <- cbind(yields2$FIPS, Year2015)
#Rename the columns so R knows what they are:
colnames(predictors)<-c("FIPS", "Year")
#Calculate predictions!
predictions2015 <- predict.lm(model,newdata = predictors)r/R_Programming • u/[deleted] • Jan 26 '18
the model I want to test is " Birth weight=Beta(0)+Epsilon"
Since the usual code is lm(y~x,dataset), what do I replace x with when I don't have any predictors.
r/R_Programming • u/[deleted] • Oct 03 '17
So, where did you start? What resources did you use? How long did it take you to feel confident you can do a proper statistical analysis in R on your own?
r/R_Programming • u/anyworld • Sep 19 '17
r/R_Programming • u/mrpsonglao • Sep 14 '17
r/R_Programming • u/hungrymonkeyx3 • Aug 24 '17
Hello Reddit users, I am learning R programming and have a quick few questions. Today I will be going through some tutorials via R later today but yesterday I finally figured how to import a excel data into R. The question is how can I or where can I learn formulas/functions how to manipulate or use the excel data. For example with a load of temperature data with 12months. I only want to see/print all temperature data that goes above 80F only and don't want to see anything else(almost like cropping all the needed data for me). Or I want the average of all data that goes above 85F and only occurs on the month of September at the same time.
r/R_Programming • u/Trek7553 • Nov 10 '16
Are there any sentiment analysis packages? This one keeps coming up when I search but it doesn't look maintained.
I would like to analyze a large number of forum posts and give them a score (mainly positive or negative, but knowing things like anger, frustration, etc. would be even better). What is the best way to go about this? I do not currently have any pre-labeled training data, it is just raw text.
r/R_Programming • u/fooliam • Sep 12 '16
Hi guys. I'm trying to figure out the mean number of anti-doping tests administered to UFC athletes, grouped by their nationality. I downloaded spreadsheet data from here.
Here is the relevant code I've tried:
data <- read.csv("C~/ufc_testing_data_01.csv", header = TRUE)
means <- aggregate(data$Total ~ data$nat, FUN = mean)
I receive:
Error in model.frame.default(formula = data$Total ~ data$nat) : invalid type (NULL) for variable 'data$nat'
What am I doing wrong/How do I accomplish what I'm trying to do?
Thanks for the help
r/R_Programming • u/DPayne94 • Jan 18 '16
Hey guys does anybody know how to do this in R? here is my code from part d:
# Based on p-values, our intercept and x2 are statistically
# insignificant, as they are greater than 0.05 (from 1.c)
# Will drop our intercept and x2 and run a new
# restricted regression model2.R (R: Restricted)
model2.R <- y ~ 0 + x1
#Running regression on new restricted model
reg.model2.R <- lm(formula = model2.R, data = as1data1)
summary(reg.model2.R)
#Analysis of Variance for test statistic and P-value
anova(reg.model1.UR, reg.model2.R)
#Test-statistic: 1.0903
#p-value: 0.3365
#Our high p-value indicates that we fail to reject the null
# hypothesis that our intercept (beta0) and x2 have joint
# significance. beta0 and x2 are statistically insignificantI now have to do what I believe is a monte carlo simulation but I don't have a clue how to perform it in R as I have very little programming experience. Any help is much appreciated and here is the question in full.
Estimate the model chosen in d) for 50 randomly drawn samples of size T=100. Note that you should sample without replacement. For each of the randomly drawn samples, store of the estimates of Beta and its standard error. At the end you will have 50 Beta's and corresponding standard errors. Calculate and plot the cumulative average for both.
r/R_Programming • u/netpumber • Feb 23 '18
Hi.
I'm having a matrix like the folwing
i j value
[1,] "3" "5" "0.259310471976401"
[2,] "3" "6" "0.294447757145722"
[3,] "3" "3" "0.189856415074712"
[4,] "3" "1" "0.0883815317200489"
[5,] "1" "6" "0.0415373072420073"
[6,] "3" "2" "0.138271823758895"
[7,] "2" "6" "0.0644122383252818"
[8,] "3" "4" "0.0542665740009899"
[9,] "4" "2" "0.0308920391871405"
[10,] "2" "3" "0.0179935306784727"
[11,] "1" "3" "0.00331858407079646"
[12,] "2" "2" "0.0411202229889999"
[13,] "2" "4" "0.025183103850682"
[14,] "4" "5" "0.0218544361243476"
[15,] "4" "3" "0.00434001163070121"
[16,] "1" "4" "0.00697017822481031"
[17,] "2" "5" "0.0993719826435549"
[18,] "1" "5" "0.0384615384615385"
[19,] "4" "1" "0.00425893177697929"
[20,] "1" "2" "0.00219826498404513"As you can see for some i,j pairs there is an inverse such pair. For example for i = 3 , j = 1 , there is a pair with i = 1 , j = 3.
Here is what I want to achieve.
For every i,j pair to subtract its inverse value and get the absolute value of the subtraction. For those pairs that have no inverse pair, 0 is subtracted from them.
Here are a couple of examples:
For i = 3 , j = 5 there is no inverse pair (i = 5, j = 3) and thus the calculation becomes:
abs( 0.259310471976401 - 0 )
For i = 3, j = 1 there is an inverse pair on the matrix with i = 1, j = 3 and thus the calculation is going to be :
abs( 0.0883815317200489 - 0.00331858407079646)
I approached this, by writing a bunch of code full of for loops and its hard to read and be edited.
So I was wondering if there is another more efficient way to do something like that, by using aggregate, apply or something else.
Any idea is welcome.
r/R_Programming • u/PsychSilvia • Jan 16 '18
Hi, I am trying to learn how to use R and I'd like to run simple/multiple/logistic regressions but I am stuck right at the beginning. I have succesfully loaded an spss database in R using this code:
> library(foreign)
> data<-read.spss("new long an.sav", use.value.labels=TRUE, to.data.frame=TRUE)
re-encoding from UTF-8
>dataThen, I was trying to specify the data file I want to undertake my regressions on by doing as following:
> newlongan<-read.delim("new long an.sav", header = TRUE)However, the following error messages comes up and I am not sure how to solve them:
Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 'new long an.sav'I have got car, boot and QuantPsyc installed. Do you have any idea? Thanks
Silvia
r/R_Programming • u/QualityJacks • Jan 03 '18
r/R_Programming • u/fasnoosh • Nov 26 '17
Does a pretty nice job of running some summaries on a dataset to show the structure of the columns (nulls, unique values, data distribution)