Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hey guys I'm having trouble with R and which codes to use (im a newbie):
So I have some data, I've performed a simple linear regression (SLR), however I found that this doesn't give me the relationship I want.
So I performed another SLR analysis using the log (base 'e') of both the variables and it seems to be a better fit.
My question is that what codes do I use to include plot by log SLR onto my original data (into a smooth curve) i.e. how do I fit the new data, with a log scale, onto my original data?
From what I understand I use the following:
1) plot(x,y) <-- Original data
2) lines(fitted(exp(____))) <-- Not sure about what to do here
If you guys could help me that would be great!
Welcome to StackOverflow!
To get better help around here I recommend you to read and follow How to make a great R reproducible example? the next time you have a question. This way you can increase the quality of your question significantly. And while creating a reproducible example one often solves the problem on its own.
Anyways, I created a sample model that I assume fits your situation quite well:
sampledata <- data.frame(x=1:50, y=1.1^(1:50+rnorm(50)))
model <- lm(log(y) ~ x, sampledata)
summary(model)
Plotting the model using R's default tools is now easy:
plot(sampledata$x, sampledata$y)
lines(sampledata$x, exp(predict(model)))
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
One task of Machine Learning / Data Science is making predictions. But, I want to get more insights in the variables of my model.
To get more insights, I tried different methods:
Logistic Regression (The output provides some 'insights' in the influence of the different variables, see: Checking interpretation of GLM summary in R)
The xgb.plot.importance function applied on a Boosting Tree, see picture below (applied on the Titanic Data Set).
And I saw a great article (but unfortunately, it is not working) how to explain a boosting tree (see: https://medium.com/applied-data-science/new-r-package-the-xgboost-explainer-51dd7d1aa211).
My question: are there other methods to give yourself (or even better: the business) more insights about which variables have a influence on the target variable? And of course: is the influence positive/negative and how big is it?
You could also try to use lasso regression (https://stats.stackexchange.com/questions/17251/what-is-the-lasso-in-regression-analysis), which basically selects the variables that influence the response variable mostly.
The glmnet package provides support for this type of regression.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have this data frame made in R :
Technical Junior Entry-Level Product Owner Technical Leader Senior
Professional 2,236 3,581 3,781 3,654 4,454
Communication 2,619 3,333 4,285 4,190 4,952
Innovation 3,625 4,208 4,500 4,000 4,791
And I want to plot something like that in R (I have made this in Excel)
Radar plot made in excel
Please help me to make this graph through R cause I failed making it with ggplot, ggtern, plotrix and other libraries I cannot manage properly.
I did it very easily using fmsb::radarchart(). Note I had to remove the commas first from your data, which I then read in as df. I also had to add rows for the min and max to reproduce your Excel plot.
library(fmsb)
df1 <- data.frame(t(df))
dfminmax <- rbind(rep(max(df1), 3) , rep(min(df1), 3) , df1)
radarchart(dfminmax)
You're going to want to tweak the settings to make it look better. Use ?radarchart to find out all the options.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have the data as below and i need to identify the distribution of the data. pls help.
x <- c(37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40)
A neat approach would involve using fitdistrplus package that provides tools for distribution fitting. On example of your data.
library(fitdistrplus)
descdist(x, discrete = FALSE)
Now you can attempt to fit different distributions. For example:
normal_dist <- fitdist(x, "norm")
abs subsequently inspect the fit:
plot(normal_dist)
As a generic point I would suggest that you have a look at this discussion at Cross Validated, where the subject is discussed at lengths. You may be also willing to have a look at a paper by Delignette-Muller and Dutang - fitdistrplus: An R Package for Fitting Distributions, available here if you are interested in a more detailed explanation on how to use the Cullen and Frey graph.
First, thing you can do is to plot the histogram and overlay the density
hist(x, freq = FALSE)
lines(density(x))
Then, you see that the distribution is bi-modal and it could be mixture of two distribution or any other.
Once you identified a candidate distribution a 'qqplot' can help you to visually compare the quantiles.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am new to r and have a data set containing a column with 3 states (1,2,3). The problem is i dont know to split the data set with respective dummy variables as to create box plots and ultimately a linear model.
PLease help!! :'(
So I think you can specify which feature is categorical.
Say
data<- read.csv(filename)
data$feature <- factor(data$feature)
Where feature is the feature you want to convert to categorical data?
Is that what you are looking for?
If I get your problem, you have 2 columns, one with factor levels (1, 2, 3) in your example, and another response variable. Is there it? (An example with part of your data would be very helpful). In any case, if your data has this structure you don't need to split it. For a boxplot just run
boxplot(data$variable~data$factor)
You can use the same approach for a linear model:
lm(data$variable~data$factor)
If your data has other structure, you will need to explain it before someone can give further help...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Fitting repeated measures in R, convergence issues. I have the following fit which is one of many datasets and it doesn't converge. I do other sets that do. This dataset and model work in SAS... Could I get some direction in what to do to have this work in R? Things to look at (matrices,option settings,a reference on this topic for r/splus ...).
fit.gls <- gls(resp~grpnum+grpnum/day,data=long, corr=cormat,na.action=na.omit)
Error in glsEstimate(object, control = control) :
computed "gls" fit is singular, rank 62
I have read the following and still trying to work thru it...
Converting Repeated Measures mixed model formula from SAS to R
The problem is the data. gls needs to invert a matrix to work (see Wikipedia for the formula to estimate the covariates). For you particular data set, that matrix is not invertible.
You can allow for singular values to be allowed with the control argument:
fit.gls <- gls(resp~grpnum+grpnum/day,data=long, corr=cormat,na.action=na.omit,
control = list(singular.ok = TRUE))
Be careful with this as you may get bad results! Always check the model fit afterwards.
Look at the help for gls and glsConrol for more details about options.